我怎么能嵌入S3托管PDF?而不必在浏览器自动下载?而不必、浏览器、我怎么能、PDF

2023-09-11 23:49:09 作者:非买品

我的服务器的nod​​e.js,但我发送一个网址到PDF托管在S3。使用Chrome,甚至当嵌入一个div或iframe的PDF自动下载。我怎样才能迫使它被嵌入?

一个链接到我的S3存储桶一个PDF: http://ws902.s3.amazonaws.com/pdf_1367897334399.pdf

-

code我使用的是正常工作时,它是一个本地PDF ...

 < IFRAME SRC =myfile.pdfWIDTH =100%的风格=高度:20em>< / IFRAME>
 

 < D​​IV ID =PDF><对象数据=myfile.pdf类型=应用程序/ PDF>< /对象>< / DIV&GT ;
 
Chrome浏览器官方Dev版下载 Chrome浏览器开发版 V84.0.4147.13

解决方案

解决的办法是发送文件头的文件,以S3。 S3服务的文件具有相同的MIME类型,因为它被上传。默认情况下,这是字节,所以我改成了应用程序/ PDF格式。

使用的Node.js和诺克斯:

 标题:{'的X AMZ-ACL:公众阅读,内容类型:应用程序/ PDF'}
 

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>

解决方案

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