views:

85

answers:

1

I have this situation where we have media files stored on a global CDN. Our web app is hosted on it's own server and then when the media assets are needed they are called from the CDN url. Recently we had a page where the user can download file attachments, however some of the file types were opening in the browser instead of downloading (such as MP3). The only way around this was to manually specify the HTTP response to attach the file but the only way I could achieve this was to download the file from CDN to my server and then feed it back to the user, which defeats the purpose of having it on the global CDN. Instead I am wondering if there is some client side solution for this?

EDIT: Just found this somewhere, though I'm not sure if it will work right in all the browsers?

<body>
<script>
function downloadme(x){
myTempWindow = window.open(x,'','left=10000,screenX=10000');
myTempWindow.document.execCommand('SaveAs','null','download.pdf');
myTempWindow.close();
}
</script>

<a href=javascript:downloadme('/test.pdf');>Download this pdf</a>
</body>

RE-EDIT: Oh well, so much for that idea -> http://stackoverflow.com/questions/833015/does-execcommand-saveas-work-in-firefox/833024#833024

+1  A: 

Does your CDN allow you to specify the HTTP headers? Amazon cloudfront does, for example.

Lou Franco
Looking into this now, on Amazon are you able to specify different HTTP headers for different directories? I couldn't do an all encompassing change like that or other things would be broken.
shogun
Looks like it's per file, but there's an API to do more broad changes (and clients). I don't use it, but I looked it up and you can add custom HTTP headers per file.
Lou Franco