Question:
Im uploading some images to S3, how can I check if it was a successful transfer?
Here is my code. I screw up the access key on purpose so the files do not upload, how can I catch this error and act upon it?
The code below does not catch anything, even though the images fail to upload.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$this->commands[] = $this->s3->getCommand('PutObject', [ 'Bucket' => env('AWS_BUCKET'), 'Key' => $name, 'Body' => $img, 'ContentType' => $mime, 'ACL' => 'public-read' ]); $pool = new CommandPool($this->s3, $this->commands); $promise = $pool->promise(); try { $result = $promise->wait(); } catch (AwsException $e) { var_dump($e) } |
Im using php sdk 3.0
Answer:
I am also using PHP SDK 3.0 and was able to get the result of the upload using the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$result = $s3Client->putObject(array( 'Bucket' => $bucketName, 'Key' => $backupFileName, 'SourceFile' => $backupFile, )); $code = $result['@metadata']['statusCode']; $uri = $result['@metadata']['effectiveUri']; if ($code === 200) { // Success code here } |