how to implement save as when downloading wav file to local machine in mvc

117 Views Asked by At

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

1

There are 1 best solutions below

3
On BEST ANSWER

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