[英]boto s3 bucket object filter with prefix and delimiter
I have a bucket with the following key structure: 我有一个具有以下主要结构的存储桶:
path/to/file1
path/to/file2
path/of/file3
path/of/file4
And I would like to be able to get the list of "folders" inside path
. 我希望能够获得
path
内的“文件夹”列表。 The actual use case has many "subfolders", so I need to filter the listing. 实际的用例有许多“子文件夹”,因此我需要过滤列表。 Ideally, I only want to receive two entries:
to
and of
. 理想情况下,我只想接收两个条目:
to
和of
。
Using boto3, I was expecting the two following calls being basically equal, ie that the listing of both yields the same result: 使用boto3,我期望以下两个调用基本相等,即,两个列表产生的结果相同:
Using the bucket returned by the S3 resource 使用S3资源返回的存储桶
s3 = boto3.resouce('s3')
bucket = s3.Bucket('bucketname')
bucket.objects.filter(Prefix='path/', Delimiter='/').all()
and the underlying client 和底层客户
s3 = boto3.resouce('s3')
s3.meta.client.list_objects(Bucket='path', Prefix='', Delimiter='/')
However, the first returns an emtpy list, while the second returns a JSON with the CommonPrefixes
key having the two entries. 但是,第一个返回一个空列表,而第二个返回一个带有
CommonPrefixes
键的JSON,其中包含两个条目。
Question: What do I miss? 问题:我想念什么?
from https://github.com/boto/boto3/issues/134#issuecomment-116766812 来自https://github.com/boto/boto3/issues/134#issuecomment-116766812
The reason that it is not included in the list of objects returned is that the values that you are expecting when you use the delimiter are prefixes (eg
Europe/
,North America
) and prefixes do not map into the object resource interface.未将其包含在返回的对象列表中的原因是,使用分隔符时期望的值是前缀(例如
Europe/
,North America
),并且前缀未映射到对象资源接口中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.