不存在任何方法,这boto3,但你可以复制到自己覆盖的文件。
要做到这一点使用过boto3 AWS的低级别的API,这样做:
s3 = boto3.resource('s3')
api_client = s3.meta.client
response = api_client.copy_object(Bucket=bucket_name,
Key=key,
ContentType="application/pdf",
MetadataDirective="REPLACE",
CopySource=bucket_name + "/" + key)
的MetadataDirective="REPLACE"
真可谓是必需的S3覆盖文件,否则你将得到一个错误消息说This copy request is illegal because it is trying to copy an object to itself without changing the object's metadata, storage class, website redirect location or encryption attributes.
。
或者你可以使用copy_from
,在评论中指出由佐敦菲利普斯:
s3 = boto3.resource("s3")
object = s3.Object(bucket_name, key)
object.copy_from(CopySource={'Bucket': bucket_name,
'Key': key},
MetadataDirective="REPLACE",
ContentType="application/pdf")
来源
2016-06-10 10:35:28
leo
复制也在资源中。 [docs](http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Object.copy_from) –
@JordonPhillips更好,谢谢!如果你想补充说,作为答案,我会接受 – leo