Skip to content
Advertisement

php s3 sdk – how to get object’s latest version

I’m trying to get latest version of a given object. I tried using this function listObjectVersions but couldn’t get it to work like I want. It lists all the files, with their versions, on my bucket.

$fileVersion = $s3Client->listObjectVersions([
    'Bucket' => 'bucketname',
    'Key' => 'folder/file.jpeg' // get all versions of this file. though, this doesn't work
  ]);

Advertisement

Answer

Listing objects in your buckets

$iterator = $client->getIterator('ListObjects', array(
    'Bucket' => $bucket,
    'Prefix' => 'foo'
));

foreach ($iterator as $object) {
    echo $object['Key'] . "n";
}

More : https://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-s3.html#listing-your-buckets

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement