0

I am interested in downloading mp3 files from remote server (CDN) URL. Unfortunately it does not work when I simply put this URL as the "href" for a "button" or "a" HTML element; the file gets just open/streamed in new tab. How can I force downloading it using javascript ? or else if there is a python server-side based solution ?

Thanks!

Medouss
  • 13
  • 3
  • Does this answer your question? [JavaScript/jQuery to download file via POST with JSON data](https://stackoverflow.com/questions/3499597/javascript-jquery-to-download-file-via-post-with-json-data) – Ruben Helsloot Nov 02 '20 at 20:17

1 Answers1

0

If your remote server is of a different origin, this is not possible. See here. Your only options are:

  1. Setting the Content-Disposition header of the CDN's responses to attachment
  2. Changing the CORS policy of the CDN to allow downloading in JavaScript

If your remote server is of the same origin, the download attribute should do what you want:

<a href="URL" download>text</a>
BrownieInMotion
  • 1,162
  • 6
  • 11