ListObjectsRequest request = new ListObjectsRequest().withBucketName(bucketName);
ObjectListing listing = null;
while((listing == null) || (request.getMarker() != null)) {
listing = s3Client.listObjects(request);
// do stuff with listing
request.setMarker(listing.getNextMarker()); //ALSO STORE MARKER FOR FUTURE USE
}
我这样做是为了消耗文件夹中的所有文件。现在一段时间后,我想使用存储的标记来仅获取该文件夹中写入的新文件。这行得通吗?
最佳答案
这对你没有帮助,原因如下:
- 标记只是一个词汇标记。对象键按词法(“字母”)顺序(按对象键的 utf-8 编码表示形式进行二进制排序)返回,而不是按对象创建的顺序。
- 在最后一个响应中,响应不会被截断,因此下一个标记应为 null 或不设置。
来自SDK实际调用的服务的API引用:
NextMarker
When the response is truncated (that is, the
IsTruncated
element value in the response is true), you can use the key name in this field as a marker in the subsequent request to get next set of objects. Amazon S3 lists objects in UTF-8 character encoding in lexicographical order.https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGET.html
关于amazon-web-services - 在 AWS s3 中,我可以获得使用我存储的最后一个标记写入的最新文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48538371/