指定内容类型的AWS PHP的上传功能 [英] Specify Content-Type in AWS PHP's upload function

查看:158
本文介绍了指定内容类型的AWS PHP的上传功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我迁移我的code从AWS PHP SDK1到SDK2(的https:// github上.COM / AWS / AWS-SDK-PHP )。

I am migrating my code from AWS PHP SDK1 to SDK2 (https://github.com/aws/aws-sdk-php).

我有一个图片上传。 在我的previous版本,我会指定的Content-Type我的形象的,像这样:

I have an image uploader. In my previous version, I would specify the Content-Type of my image like so:

$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-元的contentType的名字,而'的Content-Type的值为默认的'二元/ octet-流。

I've tried different spellings of ContentType, in the S3 site it modifies the name to look like 'x-amz-meta-contenttype', while the value of 'Content-Type' is the default 'binary/octet-stream'.

我也试着使用EntityBody功能,但同样的结果:

I've also tried using the EntityBody feature, but same results:

$response = $this->s3->upload(
                    $this->bucket, 
                    $to, 
                    EntityBody::factory($file_resource), 
                    'public-read',
                    array('params' => array('Metadata' => array('ContentType'=>$mime)))
                    );

我如何设置内容类型在这个新的API?

How do I set the content-type in this new API?

编辑:我看到某处的文件中:

I see somewhere in the documentation:

在AWS SDK的PHP将尝试自动确定最   用于存储对象​​适当的Content-Type头。如果你是   使用不常见的文件扩展名和您的Content-Type头不   自动添加的,你可以通过一个加Content-Type头   的ContentType选项到操作

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的仪表板,它们被上传为二进制/八位字节流。关于他们的第二点,我试过阵列与ContentType的我不知道为什么它不工作的许多组合...

First off, I am uploading simple images, yet according to my S3 dashboard, they are uploaded as 'binary/octet-stream'. About their second point, I've tried many combinations of arrays with 'ContentType' I'm not sure why it's not working...

推荐答案

最后,这套方案的工作:

At the end, this set of options worked:

array('params' => array('ContentType' => $mime))

无需元

这篇关于指定内容类型的AWS PHP的上传功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆