Java – AWS S3 – lists all objects in folders without prefixes

I encountered a problem retrieving all objects (file names) in folders in AWS S3 This is my code:

ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
            .withBucketName(bucket)
            .withPrefix(folderName + "/")
            .withMarker(folderName + "/")

    ObjectListing objectListing = amazonWebService.s3.listObjects(listObjectsRequest)

    for (S3ObjectSummary summary : objectListing.getObjectSummaries()) {
        print summary.getKey()
    }

It returns the correct object with a prefix, such as foldename / filename

I know I can use Java or substring to exclude prefixes, but I just want to know if there are methods in the AWS SDK

Solution

That's not true Linked is a list of all available methods The reason behind this is the S3 design S3 has no subfolders Instead, it's just a list of files, where the file name is "prefix" plus the file name you want The GUI displays data similar to the window stored in "folder", but there is no folder logic in S3

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/S3ObjectSummary.html

The best way is to use "/" to split and take out the last object in the array

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>