I have search and found multiple question about it but every time when I try these responses I always download only one file or an alias.
I try a code to make download file (.h264 and .json), it seems work for some people:
- Download multiple files with a single action
- How can I let a user download multiple files when a button is clicked?
My last try is that:
function(uri, data, name) {
let link = document.createElement("a");
link.download = name;
link.href = 'data:'+data+';charset=utf-8;base64,'+uri;
link.target = "blank_";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
uri
is the data of my file get before with axios.
data
is the mime type.
This function is used here:
ListPath.forEach(path => {
axios.all([axios.get(path+".h264"), axios.get(path+".json")]).then((data) => {
console.log(data[0], data[1]);
Utils.downloadFile(data[0].data, 'video/H264', "movie.h264");
Utils.downloadFile(data[1].data, 'application/JSON', "data.json");
}).catch(error => console.log(error))
})
And when I click to download one thing (one h264 and his json associated) it try to download only json and failed ("Network error") and redirect to about:blank
. If I put in comment the json line it download nothing but redirect too.
I have also tried the method with window.open()
, so code like this:
ListPath.forEach(path => {
window.open(path+".h264", '_blank');
window.open(path+".json", '_blank');
})
Here the h264 video is download, but it only give an alias of the real link (Like if we download our file on http://mywebsite.com/data.json
and in the file it give one line with http://mywebsite.com/data.json
) and for the json it was only display on other tab.
I'm using chrome under macOS for testing.
I've also try the js-download-file
npm module but is the same issue than before.