AWS S3-列出文件夹中没有前缀的所有对象 [英] AWS S3 - Listing all objects inside a folder without the prefix

查看:277
本文介绍了AWS S3-列出文件夹中没有前缀的所有对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在检索AWS S3的文件夹内的所有对象(文件名)时遇到问题.这是我的代码:

I'm having problems retrieving all objects(filenames) inside a folder in AWS S3. Here's my code:

ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
            .withBucketName(bucket)
            .withPrefix(folderName + "/")
            .withMarker(folderName + "/")

    ObjectListing objectListing = amazonWebService.s3.listObjects(listObjectsRequest)

    for (S3ObjectSummary summary : objectListing.getObjectSummaries()) {
        print summary.getKey()
    }

它返回正确的对象,但其中带有前缀,例如文件夹名称/文件名

It returns the correct object but with the prefix in it, e.g. foldename/filename

我知道我可以只使用java或子字符串来排除前缀,但我只是想知道AWS开发工具包中是否有针对它的方法.

I know I can just use java perhaps substring to exclude the prefix but I just wanted to know if there is a method for it in AWS SDK.

推荐答案

没有.链接是所有可用方法的列表.其背后的原因是S3设计. S3没有子文件夹".相反,它只是文件列表,其中文件名是前缀"加上所需的文件名. GUI显示的数据类似于存储在文件夹"中的窗口,但是S3中没有文件夹逻辑.

There is not. Linked is a list of all the methods that are available. The reason behind this is the S3 design. S3 does not have "subfolders". Instead it is simply a list of files, where the filename is the "prefix" plus the filename you desire. The GUI shows the data similar to windows stored in "folders", but there is not folder logic present in S3.

http://docs.aws.amazon .com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/S3ObjectSummary.html

您最好的选择是用"/"分隔,并获取数组中的最后一个对象.

Your best bet is to split by "/" and to take the last object in the array.

这篇关于AWS S3-列出文件夹中没有前缀的所有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆