Issue with downloading PDF from S3 on Chrome Issue with downloading PDF from S3 on Chrome google-chrome google-chrome

Issue with downloading PDF from S3 on Chrome


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).

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.

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

Alternative (for authenticated requests)

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:

Note

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


There is an html based solution to this. Since chrome is up to date with HTML5, we can use the shiny new download attribute!

<a href="http://www.domain.com/painful.pdf">Broken</a>
<a href="http://www.domain.com/painful.pdf" download="notsopainful">Works</a>