-1

I can connect to my ovh storage:

$s3Client = new S3Client(['profile' => 'default','endpoint' =>'http://storage.sbg.cloud.ovh.net', 'region' => 'SBG','version' => latest','credentials' => array('key' => $key,'secret' => $secret,)]);

and list all my containers

$result = $s3Client->listBuckets();var_dump($result);)

But I cannot create a new one:

$s3Client->createBucket(array('Bucket' => 'cont1',));

=> So I reate it on OVH web interface :swift,SBG,private,cont1. When I would like to upload a file in this new container :

$result = $s3Client->upload('cont1', 'test.123', fopen($file_name, 'rb'), 'public-read');

I get :

PHP Fatal error:  Uncaught exception 'Aws\\S3\\Exception\\S3Exception' with message 'Error executing "PutObject" on "http://moncontainer.storage.sbg.cloud.ovh.net/test.zip";
AWS HTTP error: Client error: `PUT http://moncontainer.storage.sbg.cloud.ovh.net/test.zip` resulted in a `400 Bad Request` response:\n\nMalformedXMLThe XML you provided was not well-formed (truncated...)\n MalformedXML (client): The XML you provided was not well-formed or did not validate against our published schema - \nMalformedXMLThe XML you provided was not well-formed or did not validate against our published schematx7bd76ec0ba114f32951bb-0061d553da'\n\nGuzzleHttp\\Exception\\ClientException: Client error: `PUT http://moncontainer.storage.sbg.cloud.ovh.net/test.zip` resulted in a `400 Bad Request` response:\n\nMalformedXMLThe  in /home/SrvWeb/BackupOVH/Proc/JSR/aws/Aws/WrappedHttpHandler.php on line 195

but if I put 'cont1/' (with slash)

$result = $s3Client->upload('cont1/', 'test.123', fopen($file_name, 'rb'), 'public-read');

an object is created in 'cont1' but named '/test.123'

What is the good way to create a container and how to upload a file with the correct name ?

DarkBee
  • 16,592
  • 6
  • 46
  • 58
jjsteing
  • 67
  • 7

1 Answers1

0

Good news... part of the answer :

To push a file in a container with the good filename :

$containername = 'moncontainer';    
$result = $s3Client->upload($containername, $containername.'/'.basename($file_Path), fopen($file_Path, 'rb'), 'public-read');

Still investigating for the creation of the container :(

jjsteing
  • 67
  • 7