-1

使用阿里巴巴 OSS Java SDK,我只能在 Bucket 中检索最多 100 个对象。如何列出所有对象?

编译组:'com.aliyun.oss',名称:'aliyun-sdk-oss',版本:'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() + ")");
}
4

1 回答 1

0

使用下面的代码,可以列出 Bucket 中的所有对象。参考链接

        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());
于 2020-05-31T07:01:06.777 回答