This is driving me mad. I am uploading images to S3 using the php SDK. Whenever I browse to the image URL, the browser downloads the image opposed to displaying it.
I think its something to do with content type.
// Prepare to upload the file to S3 bucket. $s3->create_object($bucket, $file_name, array( 'contentType' => 'binary/octet-stream', 'acl' => AmazonS3::ACL_PUBLIC ));
Can you help?
thanks
Easiest thing to do is make them public in s3, at least read-only. If you don't want them to be public on s3, for whatever reason, you could add a cloudfront distribution that will serve the images from your s3 bucket, and you can give cloudfront access to the files, without making the images public in s3.
Reading objects without downloading them Similarly, if you want to upload and read small pieces of textual data such as quotes, tweets, or news articles, you can do that using the S3 resource method put(), as demonstrated in the example below (Gist).
By default, all Amazon S3 resources—buckets, objects, and related subresources (for example, lifecycle configuration and website configuration)—are private. Only the resource owner, the AWS account that created it, can access the resource.
Sign in to Amazon Web Services and go to your S3 Management Console. 2. Click on the name of the S3 bucket from the list. If it's still in its default access state, it should say “Buckets and objects not public” next to it.
$s3->create_object($bucket, $file_name, array( 'fileUpload' => $resized_image, 'contentType' => $_FILES['image']['type'], 'acl' => AmazonS3::ACL_PUBLIC ));
Your content type is wrong indeed. It needs to be image/jpeg for JPGs, for instance. See this site for a list: http://en.wikipedia.org/wiki/Internet_media_type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With