Ralpharama Archive. The archive is almost 20 years old, this website is no longer maintained.

Home | New Writing | Old Writing | Cooking | Technical | Wine Making | Cocktails

How to force an Amazon s3 bucket PDF to download, not open in browser

Hits 5209 | Created 2012-09-26 | Modified 2012-09-26

This took a lot of figuring out :)

Go into s3 file manager and do properties on the file. Go to Metadata, add or edit the following keys:

Key: Content-Type Value: application/pdf

Key: Content-Disposition Value: attachment

And save.

Now when you hit the s3 url, the PDF will prompt to download, and not load in the browser or Adobe Reader.

If you want to hide the location of the file, or have it pop up on a click, you can try this code (sorry, I found and adapted it from the net somewhere, if you are the original author, let me know and I'll add a link to you)

<html> <head> <title>Click to save PDF example</title> </head> <body> <script> var now = false; function saveIt(){ var elFoo = window.frames['loader_frame'].document.getElementById('external'); elFoo.document.execCommand('SaveAs','0',null); } </script> <a href="javascript:;" onClick="saveIt();">Save file</a> <br> <iframe src="http://site.com/my.pdf" id="external" name="loader_frame" style="display:none;"></iframe> </body> </html>

Make a Comment


Antispam Code (always a number)

Enter Code Above

Note: All HTML will be removed except for bold and italics. Links will not display. Line breaks are added automatically. Use <pre>...</pre> for code.


This item has the following tags:
amazon s3 pdf save as tech popup javascript

Useful? Donate for hosting costs

All content copyright (c) Ralpharama