List all objects in Alibaba OSS Bucket using its Java SDK

483 Views Asked by At

Using Alibaba OSS Java SDK, I can only retrieve maximum 100 objects in Bucket. How to list all objects?

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() + ")");
}
1

There are 1 best solutions below

0
On BEST ANSWER

Using below code, all objects from a Bucket can be listed. Reference 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());