AWS PHP SDK版本2 S3 putObject错误 [英] AWS PHP SDK Version 2 S3 putObject Error

查看:137
本文介绍了AWS PHP SDK版本2 S3 putObject错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以AWS PHP SDK 2.x库已被扑灭最近,我已经采取了火鸡一天投身到从1.5倍提升。我的第一次是升级我的S3备份类。我赶紧跑成一个错误:

So the AWS php sdk 2.x library has been put out recently and I've taken a turkey day plunge into upgrading from 1.5x. My first was to upgrade my S3 backup class. I've quickly run into an error:

Fatal error: Class 'EntityBody' not found in /usr/share/php/....my file here

试图压缩文件上传到S3桶时。我写了一个类抽象的写了一下,允许多区域的备份,所以下面引用code $到这是。

when trying to upload a zipped file to an S3 bucket. I wrote a class to abstract the writing a bit to allow for multi-region backup, so the code below references to $this are that.

$response1 = $s3->create_object(
        $this->bucket_standard,
        $this->filename,
        array(
         'fileUpload'  => $this->filename,
         'encryption' => 'AES256',
         //'acl'         => AmazonS3::ACL_PRIVATE,
         'contentType' => 'text/plain',
         'storage'     => AmazonS3::STORAGE_REDUCED,
         'headers'     => array( // raw headers
                              'Cache-Control'    => 'max-age',
                              //'Content-Encoding' => 'gzip',
                              'Content-Language' => 'en-US'
                              //'Expires'       => 'Thu, 01 Nov 2012 16:00:00 GMT'
                            ),
          'meta'     => array(
                              'param1' => $this->backupDateTime->format('Y-m-d H:i:s'),     // put some info on the file in meta tags
                              'param2' => $this->hostOrigin
                            ) 
            )
      );

以上的1.5.x的正常工作。

The above worked fine on 1.5.x.

现在,在2.x中,我寻找到自己的文档,他们已经改变了刚才的一切(伟大的...最大的讽刺)

Now, in 2.x, I'm looking into their docs and they've changed just about everything (great...maximum sarcasm)

$s3opts=array('key'=> $this->accessKey, 'secret' => $this->secretKey,'region' => 'us-east-1');
$s3 = Aws\S3\S3Client::factory($s3opts);

所以现在我有一个新的S3对象。这里是我的2.x的语法做同样的事情。我的问题就出现了,他们已经(阴暗的)改变旧的文件上传到身体,并使其在如何实际附加文件更抽象的!我都试过,我想它做的依赖关系(狂饮或Smyfony等),但我得到上述错误(或替代数据流,如果你喜欢)每当我试图执行此。

so now I've got a new S3 object. And here is my 2.x syntax to do the same exact thing. My problem arises where they've (sinisterly) changed the old "fileupload" to "Body" and made it more abstract in how to actually attach a file! I've tried both and I'm thinking it has to do with the dependencies (Guzzle or Smyfony etc), but I get the error above (or substitute Stream if you like) whenever I try to execute this.

我用作曲与composer.json尝试,而aws.phar但在此之前,我到了,是有什么愚蠢的我失踪?

I've tried using Composer with composer.json, and the aws.phar but before I get into that, is there something dumb I'm missing?

$response1 = $s3->putObject(array(
        'Bucket' => $this->bucket_standard,
        'Key'    => $this->filename,
        'ServerSideEncryption' => 'AES256',
        'StorageClass' => 'REDUCED_REDUNDANCY',
        'Body' => EntityBody::factory(fopen($this->filename, 'r')),
        //'Body' => new Stream(fopen($fullPath, 'r')),

        'MetaData' => array(
                              'BackupTime' => $this->backupDateTime->format('Y-m-d H:i:s'),     // put some info on the file in meta tags
                              'HostOrigin' => $this->hostOrigin
                            ) 
      ));

感谢一如既往,

Thanks as always,

研究

推荐答案

你导入EntityBody到你的空间?

Did you import the EntityBody into your namespace?

use Guzzle\Http\EntityBody;

否则,你必须做的

Otherwise, you'd have to do

'Body' => \Guzzle\Http\EntityBody::factory(fopen($this->filename, 'r')),

这篇关于AWS PHP SDK版本2 S3 putObject错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆