简体   繁体   English

Amazon S3 PHP SDK:上载的图像具有错误的mime类型

[英]Amazon S3 PHP SDK: uploaded images have wrong mime types

I tried the following two functions, none of them works, they could upload the file to S3 but if you visit the uploaded file from a browser you could see it's being treated as application/octet-stream, that's not right... 我尝试了以下两个功能,它们都不起作用,它们可以将文件上传到S3,但是如果您从浏览器访问上传的文件,您会发现它被视为应用程序/八位字节流,这是不对的...

$s3->upload('mybucket', // bucket
    $filename, // key
    $imagebinarydata, // body
    'public-read', // acl
    array('contentType' => 'image/jpeg')); // options

And

$s3->putObject(array(
    'Bucket'        => 'mybucket',
    'Key'           => $filename,
    'ACL'           => 'public-read',
    'contentType'   => 'image/jpeg',
    'Body'          => $imagebinarydata));

I'm using the latest AWS.PHAR 我正在使用最新的AWS.PHAR

您需要按照docs中所述将大写ContentTypeputObject一起使用:

'ContentType' => 'image/jpeg'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM