Force boot through markup or JS

Suppose I have a file on CDN (Cloud Files from Rackspace) and a static html page with a link to this file. Is there a way to force this file to be downloaded (so that it does not open in the browser - for example, for mp3)?

We could make our server read the file and set the appropriate header:

header("Content-Type: application/force-download") 

but we have about 5 million downloads per month, so we would prefer the CDN to take care of that.

Any ideas?

+4
source share
4 answers

It is not possible to do this in HTML or JavaScript. Now! (See @ BruceAldriges below).

The HTTP Content-Disposition header is what tells the browser to download files and is sent by the server. You must configure the CDN to send this header using the files you want to download to the browser instead of displaying.

Itโ€™s not good, Iโ€™m completely unfamiliar with the Rackspaces cloud file service, so I donโ€™t know if they allow it, and how to do it. I just found a page from December 2009, which suggests that I didnโ€™t think, unfortunately:

Cloud files cannot serve a file with the HTTP header Content-Disposition: attachment. Thus, a download link that works great in any other service can cause the browser to directly transfer the file. This was confirmed by engineers at Rackspace.: - (

http://drupal.org/node/656714

I know that you can use the Amazons CloudFront service, since it is supported by S3 (see, for example, http://blog.cloudberrylab.com/2009/06/how-to-set-custom-http-headers-for. html )

+5
source

Yes, you can do this through the cloud file API. Using a stream of methods allows you to transfer the contents of files, setting your own headers, etc.

+1
source

Crazy idea: download via XMLHttpRequest and submit the data: URL with the type of content you want ?: P

0
source

Source: https://habr.com/ru/post/1299940/


All Articles