我在使用 Chrome 从 Amazon S3 下载 PDF 文件时遇到问题。
当我单击一个链接时,我的 Controller 将请求重定向到 S3 上文件的 URL。
它与 Firefox 完美配合,但 Chrome 没有任何 react 。
但是,如果我执行右键单击-> 将位置另存为将下载文件...
甚至将 S3 URL 复制粘贴到 Chrome 中也会导致空白屏幕......
下面是 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
我的猜测与内容类型的问题有关......但我尝试的所有方法都不起作用。
最佳答案
规范Internet media type PDF 文档实际上是 application/pdf
如 The application/pdf Media Type (RFC 3778) 中所定义- 请注意 application/x-pdf
,虽然在 Portable Document Format 中经常遇到并列为媒体类型同样,官方 Application Media Types 中也明显缺席。由 Internet Assigned Numbers Authority (IANA) 列出.
我不知道为什么以及何时 application/x-pdf
来了,但显然是Chrome PDF Plugin does not open application/x-pdf documents截至今日。
因此,您应该能够通过相应地更改存储对象的媒体类型来触发 Chrome 中的不同行为。
替代(对于经过身份验证的请求)
另一种方法是 Force a PDF to download而不是让 Chrome 尝试打开它,这可以通过触发 Content-Diposition: attachment
来完成。标题与您的 GET
请求 - 请参阅 GET Object 的 S3 文档关于如何通过 response-content-disposition
实现这一目标请求参数,特别是 response-content-disposition=attachment
如带有参数改变响应 header 值的示例请求部分所示。
这仅适用于经过身份验证的请求,请参阅请求参数部分:
Note
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.
关于google-chrome - 在 Chrome 上从 S3 下载 PDF 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9098656/