How can you tell if an object is a folder on AWS S3

后端 未结 4 1809
孤城傲影
孤城傲影 2021-02-18 22:17

I doesn\'t appear in the meta data--whether an object is a folder or not. Is there a specific method you guys on SO know of? I can\'t find anything of worth in Google search.<

4条回答
  •  一向
    一向 (楼主)
    2021-02-18 22:24

    I don´t know if this response it will be usefull after so long, but here we go:

    To resolve this problem you have to do this in java:

            List files = s3client.listObjects(bucket.getName()).getObjectSummaries();
            for (S3ObjectSummary file : files) {
                if (file.getKey().endsWith("/"))
                    System.out.println("----" + file.getKey() + " (ES CARPETA)");
                else 
                    System.out.println("----" + file.getKey() + " NO NO NO");
            }
    

    With the method "endsWith("/")" you can detect if the S3ObjectSummary is a folder or not.

    Hope this can helps someone.

    Mike

提交回复
热议问题