我可以轻松地从存储桶中下载文件,但现在我需要从S3存储桶中的特定文件夹下载。
我目前正在使用以下代码:
import boto
import boto.s3.connection
access_key = 'XXXXXXXXXXXXXXXX'
secret_key = 'XXXXXXXXXXXXXXXXXXXXXX+XXXXXXXXXXXXX'
bucket_name = 'my_Bucket'
conn = boto.connect_s3('XXXXXXXXXXXXXXXX','XXXXXXXXXXXXXXXXXXXXXX+XXXXXXXXXXXXX')
bucket = conn.get_bucket(bucket_name)
bucket_list = bucket.list()
LOCAL_PATH = '/Users/tcssig/Documents/EPG/'
for l in bucket_list:
keyString = str(l.key)
d = LOCAL_PATH + keyString
try:
l.get_contents_to_filename(d)
except OSError:
if not os.path.exists(d):
os.mkdir(d)
如何从my_uckder中的my_folder下载文件?
答案 0 :(得分:1)
将特定文件夹路径作为list()
方法
bucket_list = bucket.list(prefix='particular/folder/path')