jeudi 28 mai 2015

S3 putObject fails sometimes

i'm having some troubles here with putObject s3 , i'm using this script for uploading a file to S3 bucket :

$client = S3Client::factory(array(
       'credentials' => array(
                  'key'    => 'key',
                  'secret' => 'secret_key',
                  )
)); 
$client->registerStreamWrapper();
$targetFile = "/src/data/".$file;
if(!file_exists("s3://my-bucket/src/".$file)){
            try {
                $client->putObject(array(
                    'Bucket' => 'my-bucket',
                    'Key'    => "/src/".$file,
                    'Body'   => fopen("project".$targetFile, 'r'),
                    'ACL'    => 'public-read',
                ));
                 echo "upload success !!";
            } catch (S3Exception $e) {
                echo $e->getMessage() . "\n";
            }
 }

in the dev mode , the script was working fine , but in the prod mode it starts sometimes failing given this exception :

#0 /var/www/project/vendor/aws/aws-sdk-php/src/Aws/Common/Client/UploadBodyListener.php(89): Guzzle\Http\EntityBody::factory(false)
#11 /var/www/project/vendor/aws/aws-sdk-php/src/Aws/Common/Client/AbstractClient.php(104): Guzzle\Service\Client->__call('PutObject', Array)
#12 /var/www/project/module/Application/src/Application/Controller/MyController.php(2358): Aws\Common\Client\AbstractClient->__call('putObject', Array)
#13 /var/www/project/module/Application/src/Application/Controller/MyController.php(2358): Aws\S3\S3Client->putObject(Array)

What can be the error ? thanks.




Aucun commentaire:

Enregistrer un commentaire