Skip to content Skip to sidebar Skip to footer

Force Download Through Markup Or Js

Lets assume I have a file on a CDN (Cloud Files from Rackspace) and a static html page with a link to that file. Is there any way I can force download this file (to prevent it from

Solution 1:

There’s no way to do this in HTML or JavaScript.There is now! (Ish. See @BruceAldrige’s answer below.)

The HTTP Content-Disposition header is what tells browsers to download the files, and that’s sent by the server. You have to configure the CDN to send that header with whichever files you want to browser to download instead of display.

Unhelpfully, I’m entirely unfamiliar with Rackspace’s Cloud Files service, so I don’t know if they allow this, nor how to do it. Just found a page from December 2009 that suggests not thought, sadly:

Cloud Files cannot serve a file with the 'Content-Disposition: attachment' HTTP header. Therefore, a download link that would work perfectly in any other service may result in the browser rendering the file directly. This was confirmed by Rackspace engineers. :-(

http://drupal.org/node/656714

I know that you can with Amazon’s CloudFront service, as it’s backed by S3 (see e.g. http://blog.cloudberrylab.com/2009/06/how-to-set-custom-http-headers-for.html)

Solution 2:

Solution 3:

Yes, you can do this through the cloudfiles API. Using the method stream allows you to stream the contents of files in - setting your own headers etc.

Solution 4:

A crazy idea: download via XMLHttpRequest and serve a data: URL with the content type you want? :P

Post a Comment for "Force Download Through Markup Or Js"