我正在将我的代码从AWS
PHP SDK1迁移到SDK2(
https://github.com/aws/aws-sdk-php).
我有一个图像上传器.
在我以前的版本中,我会指定我的图像的Content-Type,如下所示:
$response = $this->s3->create_object(
$bucket,
$key,
array(
'fileUpload'=>$file_resource,
'contentType'=>$mime,
'acl' => AmazonS3::ACL_PUBLIC,
)
);
这是我的新版本:
$response = $this->s3->upload(
$bucket,
$key,
$file_resource,
'public-read',
array('params' => array('Metadata' => array('ContentType'=>$mime)))
);
我尝试过不同的ContentType拼写,在S3网站中它将名称修改为’x-amz-meta-contenttype’,而’Content-Type’的值是默认的’binary / octet-stream’.
我也尝试过使用EntityBody功能,但结果相同:
$response = $this->s3->upload(
$this->bucket,
$to,
EntityBody::factory($file_resource),
'public-read',
array('params' => array('Metadata' => array('ContentType'=>$mime)))
);
如何在此新API中设置内容类型?
编辑:我在文档中的某处看到:
The AWS SDK for PHP will attempt to automatically determine the most
appropriate Content-Type header used to store the object. If you are
using a less common file extension and your Content-Type header is not
added automatically, you can add a Content-Type header by passing a
ContentType option to the operation.
首先,我正在上传简单的图像,但根据我的S3仪表板,它们被上传为’binary / octet-stream’.关于他们的第二点,我尝试过多种具有’ContentType’的数组组合我不知道为什么它不起作用……