我嘗試過 boto3 copy 和 copy_object 方法,但我不斷收到此錯誤。
我得到的錯誤:
botocore.exceptions.ClientError: An error occurred (InvalidRequest) when calling the CopyObject operation: 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.
我使用的代碼
def copy(from_loc, to_loc):
s3_b = boto3.client("s3")
from_buc = to_loc["Bucket"]
from_key = to_loc["Key"]
to_buc = to_loc["Bucket"]
to_key = to_loc["Key"]
rsp=s3_b.copy_object(Bucket=to_buc, Key=to_key, CopySource=from_loc)
print(rsp)
我可以在 AWS UI 上做到這一點,但不能通過代碼。顯然,解決方案是更改物件元資料。但是,如果我要更改的物件是它本身,您將如何更改物件元資料并將其粘貼?
uj5u.com熱心網友回復:
您可以指定一些metadata,例如:
s3_client.copy_object(Bucket=BUCKET, Key=KEY, CopySource=SOURCE, Metadata={'foo':'bar'})
這會將現有的元資料替換為foo/bar. 如果您也希望保留現有元資料,則需要將其添加到Metadata物件中。基本上,元資料需要改變copy_object(),這是允許將物件復制到自身的充分理由。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/522516.html
標籤:Pythonpython-3.x亚马逊网络服务亚马逊-s3博托3
上一篇:如何使用EC2linux機器將檔案從本地上傳到S3存盤桶?
下一篇:軟投票機器學習演算法
