3

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.

3
  • 1
    Interesting, have you tried setTimeOut approach. Just curious. Make this function generic and independent enough and then see if you can fire it multiple times independently. Commented Dec 17, 2018 at 14:20
  • Yes I just tried it there is 2min, it works for my .h264 file but for json it's another way to get it. I just read that Chrome block multiple request. When you realise that was just simple. Commented Dec 17, 2018 at 14:26
  • You can make a function handleDownload and run this code multiple time, I have used it to download a pdf and excel file on single button click stackoverflow.com/a/54626214/9715289 Commented Feb 24, 2023 at 4:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.