Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

When I try clicking a pdf link on my website in Chrome and FF it does not do anything. I can right-click and save as but I cannot open it up within the browser. Both browsers have adobe reader enabled and works when I remove 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 fine in both IE and Opera. Any way to bypass this?

like image 346
user2233440 Avatar asked May 13 '13 20:05

user2233440


1 Answers

The reason of your problem is really obvious, but could be difficult to resolve. When you open nonKey link

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

browser gets .pdf extension at the end of the link and tries to download it. But when you have additional request params your link is not ends with .pdf and that may cause the problem.

It looks like your uploaded pdf file got no metadata for content-type. If you don't have Figure out content types automatically checkbox checked during upload, try to set content-type manually by adding metadata

content-type: application/pdf

Other idea is to make browser think that the link is ending with .pdf, so try to download with this link:

https://s3.amazonaws.com/bucket/sample.pdf?AWSAccessKeyId=a&Expires=b&Signature=c&file=sample.pdf
like image 56
Kainax Avatar answered Oct 03 '22 22:10

Kainax