不存在任何方法,這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