Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I embed an S3 hosted PDF? instead of having it download automatically in the browser?

My server is node.js but I am sending out a URL to the PDF hosted on S3. Using Chrome, the PDF downloads automatically even when embedded in a div or iframe. How can I force it to be embedded?

A link to one PDF in my S3 bucket: http://ws902.s3.amazonaws.com/pdf_1367897334399.pdf

-

Code I'm using that works fine when it's a local PDF...

<iframe src="myfile.pdf" width="100%" style="height:20em"></iframe>

or

<div id="pdf"><object data="myfile.pdf" type="application/pdf"></object></div>
like image 556
p0pps Avatar asked May 07 '13 03:05

p0pps


1 Answers

The solution was to send file headers with the file to S3. S3 serves the files with the same mime type as it was uploaded. By default this is octet, so I changed it to application/pdf.

Using node.js and knox:

headers: { 'x-amz-acl': 'public-read','Content-Type': 'application/pdf' }
like image 80
p0pps Avatar answered Sep 23 '22 17:09

p0pps