AWS PHP SDK Version 2 S3 putObject Error

So, the AWS php sdk 2.x library was recently released, and I made Native American Day a dive into modernization with 1.5x. First of all, I updated my S3 backup class. I quickly ran into an error:

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

when trying to load an archived file into an S3 bucket. I wrote a class for abstract bit writing to allow multi-regional backup, so the code below refers to $ this.

 $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('Ymd H:i:s'), // put some info on the file in meta tags 'param2' => $this->hostOrigin ) ) ); 

The above work is done on 1.5.x.

Now, in 2.x, I look through their documents and they have changed almost everything (excellent ... sarcasm)

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

So now I have a new S3 object. And here is my 2.x syntax to do the same. My problem arises where they (ominously) changed the old “file upload” to “Body” and made it more abstract in how to actually attach the file! I tried both, and I think this is due to dependencies (Guzzle or Smyfony, etc.), but I get the error above (or replace Stream if you want) whenever I try to execute this.

I tried using Composer with composer.json and aws.phar, but before I get into this, is there something stupid 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('Ymd H:i:s'), // put some info on the file in meta tags 'HostOrigin' => $this->hostOrigin ) )); 

Thanks, as always

R

+1
source share
1 answer

Have you imported EntityBody into your namespace?

 use Guzzle\Http\EntityBody; 

Otherwise you will need to do

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

All Articles