I have an s3 structure as follows:
s3bucketname -> List of first level keys -> List of second level keys -> List of third level keys -> Actual fi
Charles version is super concise! thanks @charles-menguy
I wrote an extension to support huge list through pagination.
public List getSubPathsInS3Prefix(String bucketName, String prefix) {
if (!prefix.endsWith(FILE_DELIMITER)) {
prefix += FILE_DELIMITER;
}
List paths = new ArrayList();
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
.withBucketName(bucketName).withPrefix(prefix)
.withMaxKeys(1000).withDelimiter(FILE_DELIMITER);
ObjectListing currentListing = s3Client.listObjects(listObjectsRequest);
paths.addAll(currentListing.getCommonPrefixes());
while (currentListing == null || currentListing.isTruncated()) {
currentListing = s3Client.listNextBatchOfObjects(currentListing);
paths.addAll(currentListing.getCommonPrefixes());
}
return paths;
}
http://www.lazywiz.com/uncategorized/s3-missing-api-list-sub-paths-in-the-s3-bucket/