Given an AWSS3Client, how can I get a complete list of all S3 Objects' paths?
Example:
Bucket Name: foo has 5 objects
I'd like to get a List[String] consisting of those 5 items.
How can I do this?
To do this, you can call
listObjects(bucketName).getObjectSummaries()
on the AmazonS3Client object, then iterate over that list of object summaries, calling getKey() on each one.
(The listObjects() method returns an ObjectListing, and in turn the getObjectSummaries() method returns a List<S3ObjectSummary> - and each S3ObjectSummary contains the key!)
If there are lots of objects, you also have to deal with the case that the ObjectListing is truncated, e.g. by using listNextBatchOfObjects(). See also ObjectListing.isTruncated() (javadoc).
Finally, just prepend bucketName+ "/" to each key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With