S3 putObject有时会失败

时间:2015-05-28 10:07:15

标签: php amazon-web-services amazon-s3

我在使用putObject s3时遇到了一些麻烦,我使用这个脚本将文件上传到S3存储桶:

$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";
            }
 }

在开发模式下,脚本工作正常,但在prod模式下,它启动有时会失败,因为这个例外:

#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)

错误是什么? 感谢。

0 个答案:

没有答案