Arefe
Arefe

Reputation: 12417

How to get all the files from a folder in the Amazon S3 bucket?

I would like to get all the file names and their sizes from the a particular folder of a Amazon S3 bucket. I can reach the folder with the following code, but, cant get the fiels inside.

public void GetListOfAllS3Objects() {

        System.out.println("Listing objects from the destination bucket");

        ObjectListing objectListing = s3Client.listObjects(new ListObjectsRequest().withBucketName("my-destination-bucket"));

        for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
                System.out.println(" - " + objectSummary.getKey() + "  " +
                        "(size = " + objectSummary.getSize() + ")");
        }
    }

To make the question more clear, I have a folder name "molomics" inside the mentioned bucket and I have some json and xml file there. I would like to get the names for all the files. How to do that in the most easy way ?

Upvotes: 3

Views: 8212

Answers (1)

Peter
Peter

Reputation: 5884

In your loop you have to retrieve the S3Object using getObject

Upvotes: 2

Related Questions