1

I'm trying to download multiple files from s3 in queue. But the problem occurring is the audio files are getting streamed in browser player in-spite of getting downloaded.

Note: when i'm providing local path of audios then the download function is working exactly as intended ,in all browsers but with s3 path the audio gets streamed/played in browser.

Here is what I have tried -

sending array of .mp3 paths -

$.each(jsonarray, function (key, value) {
       download_files([{download: value}]);
});  

download function-

function download_files(files) {
    function download_next(i) {
        if (i >= files.length) {
            return;
        }
        var a = document.createElement('a');
        a.href = files[i].download;
        a.target = '_parent';
        var nameArray = a.href.split('/');
        var filename = nameArray[nameArray.length-1].replace(/%20/g, " ");
        if ('download' in a) {
            a.download = filename;
        }
        (document.body || document.documentElement).appendChild(a);
        if (a.click) {
            a.click(); 
        } else {
            $(a).click();
        }
        a.parentNode.removeChild(a);
        setTimeout(function () {
            download_next(i + 1);
        }, 500);
    }
    download_next(0);
} 

Any pointers would be appreciated. Thanks

mindwares
  • 11
  • 4

1 Answers1

0

do not include .mp3 extension file name eg. <a href="/path/audioname" download>

stackoverflow
  • 82
  • 1
  • 1
  • 10