1
votes

I would like retrieve a list of all objects in a versioned bucket along with their versions in a list similar to how the AWS S3 Console does it:

AWS S3 Console

I am able to list objects in a non-versioned bucket using the advice from this SO question. However, it is not all that clear how to list them along with version IDs as S3ObjectSummary contains no versioning information. It would seem cumbersome to make separate calls to versioning methods and then try to put them together with the information contained within an S3ObjectSummary

1

1 Answers

4
votes

This looks like the closest answer I could find so far:

http://docs.aws.amazon.com/AmazonS3/latest/dev/list-obj-version-enabled-bucket.html

The relevant code snippet is here:

    ListVersionsRequest request = new ListVersionsRequest()
        .withBucketName(bucketName)
        .withMaxResults(2);
        // you can specify .withPrefix to obtain version list for a specific object or objects with 
        // the specified key prefix.

    VersionListing versionListing;            
    do {
        versionListing = s3client.listVersions(request);
        for (S3VersionSummary objectSummary : 
            versionListing.getVersionSummaries()) {
            System.out.println(" - " + objectSummary.getKey() + "  " +
                    "(size = " + objectSummary.getSize() + ")" +
                    "(versionID= " + objectSummary.getVersionId() + ")");

        }
        request.setKeyMarker(versionListing.getNextKeyMarker());
        request.setVersionIdMarker(versionListing.getNextVersionIdMarker());
    } while (versionListing.isTruncated());