我想在类似于AWS S3控制台的列表中检索版本化存储桶中所有对象及其版本的列表:
我可以使用来自this SO问题的建议列出非版本化存储桶中的对象。但是,由于S3ObjectSummary
不包含版本信息,因此并不清楚如何将它们与版本ID一起列出。单独调用版本控制方法然后尝试将它们与S3ObjectSummary
答案 0 :(得分:2)
这看起来是我到目前为止找到的最接近的答案:
http://docs.aws.amazon.com/AmazonS3/latest/dev/list-obj-version-enabled-bucket.html
相关的代码段在这里:
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());