亚马逊php上传类库,amazon-web-services – 在AWS PHP的上传功能中指定Content-Type

我正在将我的代码从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’的数组组合我不知道为什么它不起作用……

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值