phpamazon-s3

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->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


Solution

  • You need to use uppercase ContentType with putObject as described in the docs:

    'ContentType' => 'image/jpeg'