我怎么能嵌入S3托管PDF?而不必在浏览器自动下载? [英] How can I embed an S3 hosted PDF? instead of having it download automatically in the browser?

查看:149
本文介绍了我怎么能嵌入S3托管PDF?而不必在浏览器自动下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器的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 ;
 

解决方案

解决的办法是发送文件头的文件,以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' }

这篇关于我怎么能嵌入S3托管PDF?而不必在浏览器自动下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆