简体   繁体   中英

AWS S3 JAVA SDK - listObjects returns incomplete directory listings

When i use the listObjects() method, AWS returns a list of files and folders similar to this:

root/
root/projects/
root/projects/101/
root/projects/102/
root/projects/102/file1.pdf
root/images/image1.png
root/images/image2.png
root/favicon.ico

My results are not being truncated, and I'm wondering why it doesn't return a record for root/images/ I am not using the delimiter feature.

If You use as following, The List Object will have all the objects in the S3 Bucket. ListObjectsRequest lor = new ListObjectsRequest().withBucketName("myBucket"); ObjectListing objectListing = s3.listObjects(lor);

If you want to have only objects in a specified directory as you said root/images, you need to specify as

ListObjectsRequest lor = new ListObjectsRequest().withBucketName("myBucket").withPrefix("image/");

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM