Issue with Amazon S3 PDF Download Link in Chrome and Internet Explorer (IE)

In one of our project we are using Amazon S3 to store files which later use to download from web application. We have most of the files are in secure list and only accessible through web application. It was working fine for firefox but on chrome and Internet Explorer (specially PDF file) doesn’t download or open in PDF Viewer plugin instead shows about:blank page client do not have any idea what going on. For tempory solution client able to download by right click on link and selecting save link to… option but this is not everybody going to do.

After bit of googling I figureout that Amazon S3 allow specify content disposition type with below query parameter.

response-content-disposition=attachment

Just append above query param to your S3 file url and it will tell browser to force download instead of opening in PDF reader plugin. If you giving link to secure file when you had created securer signature and make sure you have added above query parameter while creating signature.

Here is sample code.
[code:cf]

<cfset var fileKey = arguments.filepath>
<cfset var epochTime = DateDiff("s", DateConvert("utc2Local", "January 1 1970 00:00"), now()) + (arguments.expiredAfter * 3600)>
<cfset var signature = "">
<cfset var cs = "GET\n\n\n#epochTime#\n/#application.az_bucket##fileKey#?response-content-disposition=attachment">
<cfset signature = createSignature(cs)>
[/code]

Hope this help.