I am trying to download multiple files that the user has selected for download. However, the browser is cancelling all but last download request. If I am increasing the delay between the requests to say about 1 second, then those files get downloaded, but even in this case, sometimes some files are missed. The files are being downloaded from amazon s3 urls(i.e. these are CORS).
I am doing this by creating an anchor element with the url and then calling the click event on it using javascript.
downloadFile(url) {
let a = document.createElement('a');
a.id = url;
// a.setAttribute('target', 'blank');
a.download = '';
a.href = url;
// firefox doesn't support `a.click()`...
// console.log('dowmloading ' + url);
a.dispatchEvent(new MouseEvent('click'));
a.remove();
}
Then on download button click event I'm doing this:
let delay = 0;
urlList.forEach(url => {
return setTimeout(downloadFile.bind(null, url), 100 * ++delay);
});
Is there a way to accomplish this?
Why is the browser cancelling the requests?