I'm relatively new to using AWS and am stuck on what I believe should be a basic task. I'm using the PHP SDK version 2 to retrieve files from one of my buckets to a temp directory on my server. According to the documentation I can use getObject to do this. Using the following code snippets I am able to retrieve the file but am having trouble saving the actual contents to the temp directory.
#1
$result = $s3->getObject(array(
"Bucket" => $s3Bucket,
"Key" => $s3Path,
"ResponseContentType" => "image/jpeg",
"SaveAs" => EntityBody::factory(fopen($saveFile, "wb"))
));
#2
$result = $s3->getObject(array(
"Bucket" => $s3Bucket,
"Key" => $s3Path,
"ResponseContentType" => "image/jpeg",
"SaveAs" => fopen($saveFile, "wb")
));
Both of these request are successful in the sense that they return the object but I am still getting a tmp file of 0 bytes. Any insight into this is greatly appriciated.
Thanks!
You can try
use Guzzle\Http\EntityBody;
$s3Client->getObject(array(
'Bucket' => $s3Bucket,
'Key' => $s3Path,
'command.response_body' => EntityBody::factory(fopen($saveFile, 'w+'))
));
Also
$result = $s3Client->getObject(array(
'Bucket' => $s3Bucket,
'Key' => $s3Path
));
file_put_contents ($saveFile, (string) $result['Body']);
Check that your Amazon Bucket and Key are correct. I got this error and discovered that the path to the AWS object was incorrect which means the file is created but no data is written to it.