s3objectsummary.java,getObjectSummaries是否将获取存储在S3存储桶中的对象数?

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 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?

解决方案

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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值