Opening .pdf files in a browser from Amazon S3 with AWS Key and Signature attributes?

When I try to click the pdf link on my website in Chrome and FF, it does nothing. I can right-click and save it, but I cannot open it in a browser. Both browsers have a built-in adobe reader and work when I delete the AWS key and signature.

https://s3.amazonaws.com/bucket/sample.pdf?AWSAccessKeyId=&Expires=&Signature= // Does not open https://s3.amazonaws.com/bucket/mypdf.pdf // Opens fine 

It works great in both IE and Opera. Any way around this?

+7
source share
1 answer

The cause of your problem is really obvious, but hard to solve. When you open the notKey link

 https://s3.amazonaws.com/bucket/mypdf.pdf 

the browser receives the .pdf extension at the end of the link and tries to download it. But when you have additional query parameters, your link does not end with .pdf, and this can cause a problem.

It looks like your downloaded pdf file did not receive metadata for the content type. If during the download the checkbox is not selected Detect content types automatically , try setting the content type manually by adding metadata

 content-type: application/pdf 

Another idea is to make the browser think that the link ends in .pdf, so try downloading from this link:

 https://s3.amazonaws.com/bucket/sample.pdf?AWSAccessKeyId=a&Expires=b&Signature=c&file=sample.pdf 
+1
source

All Articles