Created
July 11, 2015 18:40
-
-
Save jonkiddy/5401aef76338338ea3c4 to your computer and use it in GitHub Desktop.
Some example of dealing with objects in S3 buckets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://docs.aws.amazon.com/aws-sdk-php/guide/latest/service-s3.html#uploading-a-file | |
| /** | |
| * set key & secret | |
| */ | |
| $client = S3Client::factory(array( | |
| 'key' => ‘YOUR-KEY’, | |
| 'secret' => ‘YOUR-SECRET’ | |
| )); | |
| /** | |
| * list buckets | |
| */ | |
| $result = $client->listBuckets(); | |
| /** | |
| * create object | |
| * contains link to the object | |
| */ | |
| $result = $client->putObject(array( | |
| 'Bucket' => 'temp-e-assign-upload-test', | |
| 'Key' => 'stuff/here/wee/data.txt', | |
| 'SourceFile' => $pathToFile, | |
| 'Metadata' => array( | |
| 'Foo' => 'abc', | |
| 'Baz' => '123' | |
| ) | |
| )); | |
| /** | |
| * wait until object exists | |
| */ | |
| $client->waitUntil('ObjectExists', array( | |
| 'Bucket' => 'temp-e-assign-upload-test', | |
| 'Key' => 'stuff/here/wee/data.txt' | |
| )); | |
| /** | |
| * list objects in bucket | |
| */ | |
| $result = $client->listObjects(array('Bucket' => 'temp-e-assign-upload-test')); | |
| /** | |
| * get meta data of an object | |
| */ | |
| $result = $client->headObject(['Bucket' => 'temp-e-assign-upload-test', 'Key' => 'data.txt'])->toArray(); | |
| $metadata = $result['Metadata']; | |
| echo "<pre>"; | |
| print_r($result); | |
| echo "</pre>"; | |
| exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment