1

So I basically am trying to save a mp3 file that I get using jQuery. First problem is that the size of saved blob is almost 2 times bigger than the download size. Another problem is that the downloaded file isn't being recognized as a audio file. Neither in browser when adding blob as audio source neither desktop audio players.

This is the bit I use for getting and saving the data.

 $.get(fileUrl, function(song_data) {
    var blob = new Blob([song_data], {type: "audio/mpeg"});
    saveAs(blob, songName);
  });

And the blob that I make:

Blob {size: 13821949, type: "audio/mp3"}

These are also the Response Headers from the same URL that I download.

HTTP/1.1 200 OK
Date: Tue, 10 Jan 2017 18:43:42 GMT
Server: Apache
X-Powered-By: PHP/5.3.3
Cache-Control: public, must-revalidate, max-age=0
Pragma: no-cache
Content-Length: 7832555
Content-Disposition: inline; filename=5b6wgswib0.mp3
Content-Transfer-Encoding: binary
Last-Modified: Tue, 05 May 2015 08:58:26 +0300
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Content-Type: audio/mpeg
Hoffs
  • 117
  • 1
  • 8
  • 1
    Use `XMLHttpRequest`, `fetch` or [jquery-ajax-blob-arraybuffer.js](https://gist.github.com/SaneMethod/7548768). See http://stackoverflow.com/questions/38192854/recieving-a-zip-file-as-response-on-ajax-request/38193036#38193036 – guest271314 Jan 10 '17 at 19:00
  • Wow, thanks. I used fetch and it worked perfectly. Care to elaborate why $.get() is no good? – Hoffs Jan 10 '17 at 19:06
  • 1
    https://bugs.jquery.com/ticket/11461 – guest271314 Jan 10 '17 at 19:07

0 Answers0