使用其 Java SDK 列出阿里巴巴 OSS Bucket 中的所有对象
List all objects in Alibaba OSS Bucket using its Java SDK
使用阿里巴巴OSS Java SDK,我最多只能检索Bucket中的100个对象。如何列出所有对象?
compile group: 'com.aliyun.oss', name: 'aliyun-sdk-oss', version:
'3.9.1'
ObjectListing objectListing = ossClient.listObjects(bucketName);
int count = 1;
// Use objectListing.getObjectSummaries to obtain the descriptions of all objects.
for (OSSObjectSummary objectSummary : objectListing.getObjectSummaries()) {
System.out.println(count++ + " - " + objectSummary.getKey() + " " +
"(size = " + objectSummary.getSize() + ")");
}
使用下面的代码,可以列出存储桶中的所有对象。参考 Link.
do
{
System.out.println("**** ITERATION COUNT - " + itCount++ + "*****");
// The number of objects listed in each page is specified by the maxKeys parameter. If the object number is larger than the specified value, other files are listed in another page.
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName, null, nextMarker, null, 100);
result = client.listObjects(listObjectsRequest);
for (OSSObjectSummary summary: result.getObjectSummaries())
{
System.out.println("Object Count: " + objCount++ + ", Name:" + summary.getKey());
}
nextMarker = result.getNextMarker();
} while (result.isTruncated());
使用阿里巴巴OSS Java SDK,我最多只能检索Bucket中的100个对象。如何列出所有对象?
compile group: 'com.aliyun.oss', name: 'aliyun-sdk-oss', version: '3.9.1'
ObjectListing objectListing = ossClient.listObjects(bucketName);
int count = 1;
// Use objectListing.getObjectSummaries to obtain the descriptions of all objects.
for (OSSObjectSummary objectSummary : objectListing.getObjectSummaries()) {
System.out.println(count++ + " - " + objectSummary.getKey() + " " +
"(size = " + objectSummary.getSize() + ")");
}
使用下面的代码,可以列出存储桶中的所有对象。参考 Link.
do
{
System.out.println("**** ITERATION COUNT - " + itCount++ + "*****");
// The number of objects listed in each page is specified by the maxKeys parameter. If the object number is larger than the specified value, other files are listed in another page.
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName, null, nextMarker, null, 100);
result = client.listObjects(listObjectsRequest);
for (OSSObjectSummary summary: result.getObjectSummaries())
{
System.out.println("Object Count: " + objCount++ + ", Name:" + summary.getKey());
}
nextMarker = result.getNextMarker();
} while (result.isTruncated());