Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading PDF to Amazon S3 and display in-browser

I am uploading PDF's to AmazonS3 manually, using Panic Transmis and via a PHP script/API. For some reason, some display in your browser, and some force download. I have checked permission and can not seem to see any issues, Can anyone help explain how to make PDF's always display in browser ( unless the user specifies otherwise ).

I don't think it is as browser issue.

like image 484
MrPHP Avatar asked May 04 '15 03:05

MrPHP


People also ask

How do I put a PDF on my AWS S3?

In the Amazon S3 console, choose the bucket where you want to upload an object, choose Upload, and then choose Add Files. In the file selection dialog box, find the file that you want to upload, choose it, choose Open, and then choose Start Upload. You can watch the progress of the upload in the Transfer pane.

How do I view uploaded files on AWS S3?

In AWS Explorer, expand the Amazon S3 node, and double-click a bucket or open the context (right-click) menu for the bucket and choose Browse. In the Browse view of your bucket, choose Upload File or Upload Folder. In the File-Open dialog box, navigate to the files to upload, choose them, and then choose Open.

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.


1 Answers

You need to change the Content-Type and Content-Disposition.

Content-Type: application/pdf;
Content-Disposition: inline;

Using the AWS S3 console, find the file and using the context menu (right click) select Properties then it's under Metadata.

Or change this programmatically: http://docs.aws.amazon.com/AWSSDKforPHP/latest/index.html#m=AmazonS3/create_object

like image 96
well Avatar answered Sep 28 '22 13:09

well