p0pps
p0pps

Reputation: 586

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>

Upvotes: 7

Views: 6287

Answers (3)

cng.buff
cng.buff

Reputation: 575

i using iframe and work for me.

  • PDf file is placed in public aws s3

      baseURL : `${window.location.origin}/lib/pdfjs-2.10.377-dist/web/viewer.html?file=/`,
      pdfS3Url : 's3File/202411/Terms.pdf',

    <iframe
      :src="baseURL + pdfS3Url[0]"
      width="100%"
      height="300"
      type="application/pdf"
      class="doc-wrap">
    </iframe>

Upvotes: 0

JoelWass
JoelWass

Reputation: 575

To elaborate on Alex D's answer regarding node.js and uploading a public pdf to s3 using headers:

Node.js working application uploading public pdf to s3

Upvotes: -3

p0pps
p0pps

Reputation: 586

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' }

Upvotes: 10

Related Questions