0

I would like to implement an option to let the user download or save a wav file to their local machine. I currently have this:

<div id="ContextMenu">
<a id="savebtn" class="savebtn" href="~/Content/audio/sounds.wav" download="sounds.wav">Save</a>
</div>

This seems to be working when I access the website from my machine but when another user accesses the site from their machine it only opens the media player but doesn't actually saves the wav file in their local machine. Does anyone know why it's doing this and how I can fix it? Also if possible, how can I implement a "save as" so the user has the option of choosing where to save the wav file.

Thank you

Newit
  • 3
  • 6

1 Answers1

0

the actual behavior depends on the browser. I'd advice to use the Content-Disposition header (Uses of content-disposition in an HTTP response header)

Content-Disposition: attachment;  filename="sounds.wav"

it is not part of the http standard, but it is widely implemented and tells the browser to save the content instead of handling it

next to that - in the href you should not use ~ (tilde in href), use relative or absolute url of the page , e.g. ./Content/audio/sounds.wav

gusto2
  • 11,210
  • 2
  • 17
  • 36
  • So I found out it works fine in chrome but not in IE, would that make it work in IE? – Newit Sep 14 '17 at 22:35
  • I'm also still unclear how to use the content-disposition to download/save the wav file. Can you give me an example – Newit Sep 14 '17 at 22:43
  • @Newit it will work with a dynamic server (generated by a web server) not a static page loaded directly from your local filesystem. The web server have to send an http header **Content-Disposition: attachment; filename="sounds.wav"**. How to do that depends on the technology you use. It works with IE as well (from version 6.0 ) – gusto2 Sep 15 '17 at 07:19