问题下载PDF从S3在Chrome [英] Issue with downloading PDF from S3 on Chrome

查看:141
本文介绍了问题下载PDF从S3在Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Chrome从Amazon S3下载的PDF文件所面临的问题。

I'm facing an issue on downloading PDF files from Amazon S3 using Chrome.

当我点击一个链接,我的控制器将请求重定向到S3的文件的URL。

When I click a link, my controller redirect the request to the file's URL on S3.

它可以完美地与Firefox,但没有任何反应与Chrome浏览器。

It works perfectly with Firefox, but nothing happens with Chrome.

不过,如果我执行右键 - > 保存位置的将下载的文件...

Yet, if I perform a right click -> Save location as will download the file ...

和连S3网址进入Chrome浏览器的复制粘贴会导致黑屏......

And even a copy-paste of the S3 URL into Chrome will lead to a blank screen ...

下面是返回卷曲的一些信息:

Here is some information returned by curl:

Date: Wed, 01 Feb 2012 15:34:09 GMT
Last-Modified: Wed, 01 Feb 2012 04:45:24 GMT
Accept-Ranges: bytes
Content-Type: application/x-pdf
Content-Length: 50024
Server: AmazonS3

我的猜测都涉及到一个问题,内容类型...但我试过没有工作。

My guesses are related to an issue with the content type ... but all I tried didn't work.

推荐答案

的规范互联网媒体类型对于PDF文档实际上是应用程序/ PDF 中的应用程序/ PDF格式的媒体类型(RFC 3778) - 请注意,应用程序/ x-PDF ,而常见的,并列入媒体请在可移植文档格式为好,是从官方的应用媒体类型的列出了的<​​a href =http://www.iana.org /相对=nofollow>互联网编号分配机构(IANA)。

The canonical Internet media type for a PDF document is actually application/pdf as defined in The application/pdf Media Type (RFC 3778) - please note that application/x-pdf, while commonly encountered and listed as a media type in Portable Document Format as well, is notably absent from the official Application Media Types listed by the Internet Assigned Numbers Authority (IANA).

我不知道为什么,当应用程序/ x-PDF 来生活,但显然的 Chrome浏览器PDF插件不打开应用程序/ x-pdf文档的今天的。

I'm not aware of why and when application/x-pdf came to life, but apparently the Chrome PDF Plugin does not open application/x-pdf documents as of today.

因此​​,你应该能够通过改变存储的对象的媒体类型相应触发在Chrome中不同的行为。

Consequently you should be able to trigger a different behavior in Chrome by changing the media type of the stored objects accordingly.

另一种方法是将强制PDF下载代替让浏览器试图打开它,这可以通过触发内容Diposition的方式来完成:附件头与你的 GET 请求 - 请S3的文档获取对象如何实现这种通过响应内容处置请求参数,特别是响应内容处置=附件在部分证明有索取样品与参数涂改响应报头值的。

Another approach would be to Force a PDF to download instead of letting Chrome attempt to open it, which can be done by means of triggering the Content-Diposition: attachment header with your GET request - please see the S3 documentation for GET Object on how to achieve this via the response-content-disposition request parameter, specifically response-content-disposition=attachment as demonstrated there in section Sample Request with Parameters Altering Response Header Values.

这是仅适用于验证请求,不过,见的请求参数的:

This is only available for authenticated requests though, see section Request Parameters:

注意

您必须签署的请求,或者使用Authorization头   或pre-标识的URL,使用这些参数时。它们不能被用于   一个无符号(匿名)的请求。

You must sign the request, either using an Authorization header or a Pre-signed URL, when using these parameters. They can not be used with an unsigned (anonymous) request.

这篇关于问题下载PDF从S3在Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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