0

I am trying to create a page on my site such that when a user lands on the page a audio file download is initiated.

I attempted putting the following code in between my header tag

<meta http-equiv="refresh" content="1; url=MyAudioFile.mp3">

However, this doesn't start an automatic download after 1 second, rather it simply redirects the user to www.mywebsite.com/MyAudioFile.mp3. Essentially, this will result in the audio being streamed as opposed to being downloaded.

How can I modify this code to make the mp3 file automatically download as opposed to having it streamed?

Note: the reason why this is being done is because there is an email that goes out with a "download audio file" button. I want the URL of that button to point to this page that will automatically download the audio file without the user having to click on another download button.

Harif87
  • 126
  • 1
  • 10

1 Answers1

1

The web-server can be configured to handle *.mp3 files as a MIME type that will be downloaded.

Instead of audio/mpeg the MIME-type can be set to application/octet-stream.

For Apache you can configure this on a per-directory basis using a .htaccess file.

Option 1)

<FilesMatch "\.(?i:mp3)$">
    ForceType application/octet-stream
    Header set Content-Disposition attachment
</FilesMatch>

Option 2)

AddType application/octet-stream .mp3
MrYellow
  • 426
  • 6
  • 23
  • 1
    Related questions: http://stackoverflow.com/questions/14388994/forcing-a-download-using-filesmatch-in-htaccess-at-www-root http://stackoverflow.com/questions/25124279/force-mp3-file-to-download-using-http-content-disposition-attachment-in-url http://stackoverflow.com/questions/3977159/set-content-disposition-header-to-attachment-only-on-files-in-a-certain-director http://stackoverflow.com/questions/3401650/stop-mp3-file-from-streaming-in-browsers – MrYellow Oct 07 '14 at 22:31
  • Thanks for the answers - unfortunately I am using weebly and there is no way to access the .htaccess file ..... Would I able to add either of the snippets in the header tags of the HTML document and have it work? – Harif87 Oct 08 '14 at 17:21
  • Seems HTML5 has that ability using the `download` attribute. http://stackoverflow.com/a/16194104/2438830 http://svarden.se/blog/2013-04-22-right-click-and-save-as/ – MrYellow Oct 08 '14 at 20:06