1
我使用AWS PHP SDK v2.x使用下面的代碼複製S3桶之間進行對象:如何使用AWS PHP SDK v2和CopyObject設置內容處置?
<?php
try {
self::$aws->copyObject(array(
'Bucket' => $target_bucket,
'Key' => $target_key,
'CopySource' => $source_bucket . '/' . $source_key,
'Content-Disposition' => 'attachment',
//'Content-Disposition' => 'attachment; filename="' . basename($target_key) . '"'
//'ContentDisposition' => 'attachment'
//'ContentDisposition' => 'attachment; filename="' . basename($target_key) . '"'
));
} catch (Aws\S3\Exception\S3Exception $e) {
echo 'error';
}
文件複製到S3存儲沒有任何錯誤,但我無法設置的Content-Disposition
爲了強制瀏覽器下載文件而不是流式傳輸。我已經嘗試了幾個選項(註釋如上),但似乎沒有任何工作。
我甚至嘗試了Metadata
數組中傳遞的價值,即使documentation說,否則但AWS Console列出了Content-Disposition
下的元數據部分。
如果我手動更改AWS Console中的Content-Disposition
,則瀏覽器按預期下載文件。
那麼,如何正確地將值傳遞給S3對象呢? 可以我通過它使用CopyObject()
方法?
'ContentDisposition'只需要指定它的「附件」值,但是'MetadataDirective'是缺少的信息。 –