[英]Can boto's get_resource_type('s3').Object(bucket_name, key) take wildcards?
I'm very new to python. 我是python的新手。 I'm using this library that's using boto like this: 我正在使用像boto这样的库:
def get_key(self, key, bucket_name=None):
"""
Returns a boto3.s3.Object
:param key: the path to the key
:type key: str
:param bucket_name: the name of the bucket
:type bucket_name: str
"""
if not bucket_name:
(bucket_name, key) = self.parse_s3_url(key)
obj = self.get_resource_type('s3').Object(bucket_name, key)
obj.load()
return obj
I'm trying to figure out if that Object(bucket_name, key)
can take wild cards so that I can download multiple files at once. 我试图弄清楚该Object(bucket_name, key)
可以使用通配符,以便我可以一次下载多个文件。
I've copied this file and modified it so it prints out type(resource_type)
, but that just says <class 'boto3.resources.factory.s3.ServiceResource'>
. 我已经复制并修改了该文件,以便打印出type(resource_type)
,但这只是说<class 'boto3.resources.factory.s3.ServiceResource'>
。 Although I can find the source to that class, it doesn't seem to have an Object()
method in it so I don't know how to answer my question. 尽管我可以找到该类的源代码,但是它似乎没有Object()
方法,因此我不知道如何回答我的问题。
Object()
method? 如何找到该Object()
方法的源代码? Object(bucket_name, key)
take wild cards? Object(bucket_name, key)
是否使用通配符? If no, which method should I be calling instead? 如果没有,我应该改为调用哪个方法? s3 allows you to download 1 object with 1 call. s3允许您通过1次调用下载1个对象。 You have to enter the exact key to download any object. 您必须输入确切的密钥才能下载任何对象。 If you want to download multiple objects you will need to use a loop to list out all of the keys you want to download. 如果要下载多个对象,则需要使用循环列出要下载的所有密钥。 You can use list_objects_v2 to get a list of the all the keys and then filter out the list depending on your conditions. 您可以使用list_objects_v2获取所有键的列表,然后根据您的条件过滤掉该列表。 If key matches the condition, call the get_object API to download the body of the object. 如果key与条件匹配,则调用get_object API以下载对象的主体。 Note that both these calls are available on client and not resource. 请注意,这两个调用在客户端都可用,而在资源上不可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.