【发布时间】:2016-11-24 16:44:39
【问题描述】:
我正在使用AWS PHP SDK v2.x 使用以下代码在 S3 存储桶之间复制对象:
<?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() 方法来传递它吗?
【问题讨论】:
标签: php amazon-s3 aws-php-sdk