I've created a hierarchy in S3 via the AWS S3 Management Console. If I run the following code to list the bucket:
AmazonS3 s3 = new AmazonS3Client(CRED);
ListObjectsRequest lor = new ListObjectsRequest()
.withBucketName("myBucket")
.withPrefix("code/");
ObjectListing objectListing = s3.listObjects(lor);
for (S3ObjectSummary summary: objectListing.getObjectSummaries()) {
System.out.println(summary.getKey());
}
I get:
code/
code/03000000-0001-0000-0000-000000000000/
code/03000000-0001-0000-0000-000000000000/special.js
code/03000000-0001-0000-0000-000000000000/test.js
code/03000000-0002-0000-0000-000000000000/
Which is exactly what I would expect. If I add a delimiter though, so that I only list the content directly under "code/" I now don't get any sub "directories" back.
Change line above (add withDelimiter() on the end) to:
ListObjectsRequest lor = new ListObjectsRequest().withBucketName("myBucket")
.withPrefix("code/")
.withDelimiter("/");
And I now only get:
code/
I know that S3 doesn't have "directories", instead delimited keys, but this behaviour seems odd? How would I list what is only immediately below "code"?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…