6

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 -> Does execCommand SaveAs work in Firefox?

Community
  • 1
  • 1
MetaGuru
  • 42,847
  • 67
  • 188
  • 294
  • 1
    We’re assuming that you can’t configure the CDN, only upload files to it? Presumably the CDN examines the content to write HTTP headers — can that be manipulated in any way? – Josh Lee Sep 14 '10 at 17:53
  • I don't think there is any configuration like that, but I will check just in case on the off chance that there is a way to set a different delivery method for a certain folder for example. – MetaGuru Sep 14 '10 at 17:54

2 Answers2

2

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

Lou Franco
  • 87,846
  • 14
  • 132
  • 192
  • 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. – MetaGuru Sep 14 '10 at 17:57
  • 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 Sep 14 '10 at 18:21
1

I found an easy solution to this that worked for me. Add a URL parameter to the file name. This will trick the browser into bypassing it's built in file mappings. For examaple, instead of http://mydomain.com/file.pdf , set your client side link up to point to http://mydomain.com/file.pdf? (added a question mark)