Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

amazon s3 - image downloading instead of displaying in browser

Tags:

php

amazon-s3

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

like image 908
drs Avatar asked Jan 20 '11 19:01

drs


People also ask

How do I show an image from my Amazon S3 on my website?

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.

Can I read S3 file without downloading?

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

What is the default setting for S3 storage visibility?

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.

How do I access AWS S3 bucket from browser?

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.


2 Answers

            $s3->create_object($bucket, $file_name, array(                     'fileUpload' => $resized_image,                     'contentType' => $_FILES['image']['type'],                     'acl' => AmazonS3::ACL_PUBLIC             )); 
like image 89
drs Avatar answered Sep 21 '22 10:09

drs


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

like image 32
jschorr Avatar answered Sep 19 '22 10:09

jschorr