Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3 display file inline instead of force download

For some reason files in my S3 bucket are being forced as downloads instead of displaying in-line so if I copy an image link and paste it into address bar and then navigate to it, it will promote my browser to download it. Instead I actually have to click on open image to go to the url.

Any ways to change the way files are served from S3

like image 421
Cl' Avatar asked Jan 04 '13 03:01

Cl'


People also ask

How do I download content from S3 bucket?

To download an entire bucket to your local file system, use the AWS CLI sync command, passing it the s3 bucket as a source and a directory on your file system as a destination, e.g. aws s3 sync s3://YOUR_BUCKET . . The sync command recursively copies the contents of the source to the destination.

What is content disposition S3?

S3 provides multiple ways to set the Content-Disposition header of an object being downloaded, two of the main ways are: Set Content Disposition parameter on upload – works for new objects. Set response-content-disposition parameter in request – works for an existing object however requires a signed URL.

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.


2 Answers

$client->putObject(array(         'Bucket'     => 'buckname',         'Key'        => $destination,         'SourceFile' => $source,         'ContentType' =>'image/jpeg', //<-- this is what you need!         'ACL'          => 'public-read'//<-- this makes it public so people can see it     )); 
like image 126
Neo Avatar answered Sep 22 '22 11:09

Neo


You need to change the Content-Type. From the S3 console, right click on the object and select Properties then it's under Metadata. You can also do it programmatically: http://docs.amazonwebservices.com/AWSSDKforPHP/latest/index.html#m=AmazonS3/change_content_type

like image 33
gregbeaty Avatar answered Sep 25 '22 11:09

gregbeaty