Installation guide

// Grab the nested Owner/ID value from the result model using getPath()
$result = $client->listBuckets();
echo $result->getPath('Owner/ID') . "\n";
Listing objects in your buckets
Listing objects is a lot easier in the new SDK thanks to iterators. You can list all of the objects in a bucket using the
ListObjectsIterator.
$iterator = $client->getIterator('ListObjects', array(
'Bucket' => $bucket
));
foreach ($iterator as $object) {
echo $object['Key'] . "\n";
}
Iterators will handle sending any required subsequent requests when a response is truncated. The ListObjects
iterator works with other parameters too.
$iterator = $client->getIterator('ListObjects', array(
'Bucket' => $bucket,
'Prefix' => 'foo'
));
foreach ($iterator as $object) {
echo $object['Key'] . "\n";
}
You can convert any iterator to an array using the toArray() method of the iterator.
Note
Converting an iterator to an array will load the entire contents of the iterator into memory.
Downloading objects
You can use the GetObject operation to download an object.
// Get an object using the getObject operation
$result = $client->getObject(array(
'Bucket' => $bucket,
'Key' => 'data.txt'
));
// The 'Body' value of the result is an EntityBody object
echo get_class($result['Body']) . "\n";
// > Guzzle\Http\EntityBody
// The 'Body' value can be cast to a string
echo $result['Body'] . "\n";
// > Hello!
The contents of the object are stored in the Body parameter of the model object. Other parameters are stored in
model including ContentType, ContentLength, VersionId, ETag, etc...
The Body parameter stores a reference to a Guzzle\Http\EntityBody object. The SDK will store the data in a
temporary PHP stream by default. This will work for most use-cases and will automatically protect your application
from attempting to download extremely large files into memory.
The EntityBody object has other nice features that allow you to read data using streams.
Amazon Simple Storage Service
105