getObjectSummaries是否将获取存储在S3存储桶中的对象数? [英] Will getObjectSummaries get the count of objects stored in a S3 Bucket?

查看:380
本文介绍了getObjectSummaries是否将获取存储在S3存储桶中的对象数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道S3存储桶下存储的文件数.当前,ObjectListing没有诸如countnumberOfObject之类的方法.

I need to know the number of files that are stored under S3 bucket. Currently, ObjectListing doesn't has a method such as count or numberOfObject.

但是,它具有一种将返回S3ObjectSummary列表的方法.

However, it has a method that will return a List of S3ObjectSummary.

public java.util.List<S3ObjectSummary> getObjectSummaries()

由于它是List,因此我可以调用size()方法,但是假设getObjectSummaries() List的大小与存储在存储桶中的对象数量相同是正确和正确的做法吗?

Since it is a List, I can call size() method but is it accurate and right thing to assume that the size of getObjectSummaries() List is the same number of objects that are stored under a bucket?

推荐答案

否-准确地说getObjectSummaries()的大小是您收到的listObjects()结果页面中的对象数.否则,是-列表中的每个对象摘要都应对应于一个S3对象,这是正确的.

No -- it is more accurate to say that the size of getObjectSummaries() is the number of objects in the page of results from listObjects() that you received. Otherwise, yes -- it is correct that each object summary in the list should correspond to an S3 object.

AWS将大结果集的结果分页为每页1,000个结果.在一般情况下,您将需要多次拨打此电话:

AWS pages the results of large result sets to 1,000 results per page. In a general case, you will need to expect to make this call more than once:

  • 如果

  • If isTruncated() is true, call getNextMarker() to get the next marker to use in your next ListObjectsRequest to listObjects().

如果为false,则您得到的最后一个响应将是您需要处理的最后一个响应.您现在可以完成对对象的计数了.

If false, this last response you got will be the last one you need to handle. You can finish counting your objects at this point.

请记住,这对于非常大的存储桶来说不是一个很好的解决方案,因为您必须枚举整个存储桶.这是使用替代解决方案 > s3cmd ,您可以从Java调用它.

With that in mind, this isn't a great solution for very large buckets since you have to enumerate the whole bucket. Here's an alternative solution using s3cmd that you may be able to call from Java.

这篇关于getObjectSummaries是否将获取存储在S3存储桶中的对象数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆