【发布时间】:2019-01-22 21:00:57
【问题描述】:
我正在尝试将几个文件上传到 Amazon S3。我可以将文件上传到我的存储桶中。但是,该文件需要在 my-bucket-name,Folder1/Folder2 中。
import boto3
from boto.s3.key import Key
session = boto3.Session(aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
bucket_name = 'my-bucket-name'
prefix = 'Folder1/Folder2'
s3 = session.resource('s3')
bucket = s3.Bucket(bucket_name)
objs = bucket.objects.filter(Prefix=prefix)
我尝试使用此代码上传到存储桶并成功:
s3.meta.client.upload_file('C:/hello.txt', bucket, 'hello.txt')
当我尝试使用此代码将相同的文件上传到指定的 Folder2 时,失败并出现错误:
s3.meta.client.upload_file('C:/hello.txt', objs, 'hello.txt')
ERROR>>>
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid bucket name "s3.Bucket.objectsCollection(s3.Bucket(name='my-bucket-name'), s3.ObjectSummary)": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$"
那么,如何将文件上传到 my-bucket-name,Folder1/Folder2?
【问题讨论】: