I have a S3 bucket with following hierarchy:
bucketName
folder1
file1
I wanted to get all the files from folder1. I tried to do following:
ObjectListing ol = s3Client.listObjects("bucketName", "folder1");
List<S3ObjectSummary> summaries = ol.getObjectSummaries();
The problem is that summaries contains folder1/
and folder1/file1
. Where as I was hoping to get just folder1/file1
.
Looking around at the internet, I also tried following:
ListObjectsRequest req = new ListObjectsRequest().withBucketBucketName("bucketName").withPrefix("folder1/").withDelimiter("/");
But this time I got no results back for getObjectSummaries
call. When I remove withDelimiter
from above I get both folder1\
and folder1\file1
back.
Is there any way to just get folder1\file1
back?