简体   繁体   English

AWS S3 Java SDK - ListVersionsRequest 仅获取最新版本

[英]AWS S3 Java SDK - ListVersionsRequest Get Only Latest Versions

Is there any way to specify to only include the latest version of each object in the ListVersionsRequest ?有什么方法可以指定只在ListVersionsRequest中包含每个对象的最新版本? I need the version value, so a simple AmazonS3Client.listObjects(...) will not suffice because S3ObjectSummary has no version information.我需要版本值,所以一个简单的AmazonS3Client.listObjects(...)是不够的,因为S3ObjectSummary没有版本信息。

I am creating a utility that pings S3 for all objects in the versioned bucket and compares the latest version value to what the utility is already tracking.我正在创建一个实用程序,它为版本化存储桶中的所有对象对 S3 执行 ping 操作,并将最新版本值与该实用程序已经跟踪的内容进行比较。 The only solution I can think of right now is just to do AmazonS3Client.listVersions(...) , iterate through the S3VersionSummary list, handle the first most recent version then manually iterate and skip all older versions of an objet until it gets to the new key.我现在能想到的唯一解决方案就是执行AmazonS3Client.listVersions(...) ,遍历S3VersionSummary列表,处理第一个最新版本,然后手动迭代并跳过对象的所有旧版本,直到它到达新钥匙。 Is this the best solution?这是最好的解决方案吗?

Thanks谢谢

I only see two options:我只看到两个选项:

  1. Do what you described and list all versions of the data that you have.执行您描述的操作并列出您拥有的数据的所有版本。 Afterwards you'll get a list that is in order of versioning, so you'll need to know when to stop checking for versions.之后您将获得一个按版本顺序排列的列表,因此您需要知道何时停止检查版本。 I think that this can be done by iterating through the list of versions and stopping at the first islatest() call that returns false ref我认为这可以通过遍历版本列表并在第一个返回 false ref的 islatest() 调用处停止来完成

  2. You can list objects and then get the object summary for each object which will contain the version ID.您可以列出对象,然后获取每个对象的对象摘要,其中将包含版本 ID。

The return from a listVersions as specified in the link to ListVersionsRequest indicates following...从 ListVersionsRequest 的链接中指定的 listVersions 返回表明以下......

and versions are sorted from the most recent to the least recent.和版本从最新到最不最新排序。

So ask for the versions of a specific s3 key and the first result in the list is the most recent version.因此,询问特定 s3 密钥的版本,列表中的第一个结果是最新版本。

handle the first most recent version then manually iterate and skip all older versions of an objet until it gets to the new key处理第一个最新版本,然后手动迭代并跳过对象的所有旧版本,直到它到达新密钥

Instead of doing that, you can simple use isLatest() , available in S3VersionSummary您可以简单地使用 S3VersionSummary 中提供的isLatest ()而不是那样做

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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