Will getObjectSummaries get the count of objects stored in a S3 Bucket?

删除回忆录丶 提交于 2020-01-04 09:28:01

问题


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.

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

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

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?


回答1:


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 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().

  • 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.

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.



来源:https://stackoverflow.com/questions/28113605/will-getobjectsummaries-get-the-count-of-objects-stored-in-a-s3-bucket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!