![](/img/trans.png)
[英]AWS S3 gives InvalidDigest [The Content-MD5 you specified was invalid] Error while copy_object() is used
[英]S3 PHP SDK: copy_object() fails to update the header
當將標頭選項包括到copy_object時,標頭不會更新。
在我使用update_object進行單獨調用之前,標題不會更新。 我希望我做錯了什么,但是我已經以4-5種不同的方式測試了該方法,甚至進入了sdk代碼。
這是錯誤嗎?
我正在使用最新的1.4.3 SDK
這是我的電話:
$amazonS3->copy_object(
array( //Source
'bucket' => SOURCE_BUCKET,
'filename' => $source_file
),
array( //Target
'bucket' => VIDEO_BUCKET,
'filename' => $dest_file,
),
array( //Options
'acl' => AmazonS3::ACL_PRIVATE,
'headers' => array(
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment'
)
);
我自己遇到了這個問題,並通過iamdev解決了這個問題。 經過大約半天的瘋狂之后,我開始查看實際的API,而不僅僅是嘗試使用它。
在sdk.class.php的1690行中,您將看到以下內容:
if (isset($opt['metadataDirective']))
$opt['headers']['x-amz-metadata-directive'] = $opt['metadataDirective'];
unset($opt['metadataDirective']);
}
這意味着,如果您不將對象復制到自身,它將不會替換密鑰,因此不會對其進行更新。
對我有用的是在調用中的選擇中顯式設置metadataDirective,因此:
$amazonS3->copy_object(
array( //Source
'bucket' => SOURCE_BUCKET,
'filename' => $source_file
),
array( //Target
'bucket' => VIDEO_BUCKET,
'filename' => $dest_file,
),
array( //Options
'acl' => AmazonS3::ACL_PRIVATE,
'headers' => array(
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment'
),
'metadataDirective' => 'REPLACE',
);
希望這對您有用,盡管這是一篇過時的文章,並且您可能已經找到了解決方法。
最佳,HG
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.