Gets a list of all the versions of Amazon S3 objects in the specified bucket.
Access
Parameters
Parameter |
Type |
Required |
Description |
$bucket
|
string
|
Required
|
The name of the bucket to use. |
$opt
|
array
|
Optional
|
An associative array of parameters that can have the following keys:
delimiter - string - Optional - Unicode string parameter. Keys that contain the same string between the prefix and the first occurrence of the delimiter will be rolled up into a single result element in the CommonPrefixes collection.key-marker - string - Optional - Restricts the response to contain results that only occur alphabetically after the value of the key-marker .max-keys - string - Optional - Limits the number of results returned in response to your query. Will return no more than this number of results, but possibly less.prefix - string - Optional - Restricts the response to only contain results that begin with the specified prefix.version-id-marker - string - Optional - Restricts the response to contain results that only occur alphabetically after the value of the version-id-marker .preauth - integer|string - Optional - Specifies that a presigned URL for this request should be returned. May be passed as a number of seconds since UNIX Epoch, or any string compatible with strtotime() .curlopts - array - Optional - A set of values to pass directly into curl_setopt() , where the key is a pre-defined CURLOPT_* constant.returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests. |
Returns
Examples
List all object versions in a bucket.
// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);
$response = $s3->list_bucket_object_versions($bucket);
// Success?
var_dump($response->isOK());
Result:
bool(true)
List all object versions in a bucket that match the provided parameters.
// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);
$response = $s3->list_bucket_object_versions($bucket, array(
'prefix' => 'test1.txt',
'max-keys' => 1
));
// Success?
var_dump($response->isOK());
var_dump((string) $response->body->Prefix);
var_dump((string) $response->body->MaxKeys);
Result:
bool(true)
string(9) "test1.txt"
string(1) "1"
Source
Method defined in services/s3.class.php | Toggle source view (18 lines) | View on GitHub
public function list_bucket_object_versions($bucket, $opt = null)
{
if (!$opt) $opt = array();
$opt['verb'] = 'GET';
$opt['sub_resource'] = 'versions';
foreach (array('delimiter', 'key-marker', 'max-keys', 'prefix', 'version-id-marker') as $param)
{
if (isset($opt[$param]))
{
$opt['query_string'][$param] = $opt[$param];
unset($opt[$param]);
}
}
// Authenticate to S3
return $this->authenticate($bucket, $opt);
}