简体   繁体   中英

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
  ]);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM