In a sequential call:
saveAs(new Blob(...), "a.txt");
saveAs(new Blob(...), "b.txt");
saveAs(new Blob(...), "c.txt");
I got 3 download of the same file that was last set.
I think that this is due to the improper scope of the variable save_link defined in
var saveAs = saveAs || (Function (view) {
...
, save_link = doc.createElementNS ("http://www.w3.org/1999/xhtml", "a")
, can_use_save_link = "download" in save_link
...
}
The definition of the save_link object in
, FileSaver = function (blob, name, no_auto_bom) {
...
, save_link = doc.createElementNS ("http://www.w3.org/1999/xhtml", "a")
, can_use_save_link = "download" in save_link
...
}
solves the problem of multiple downloads
Please fix this problem.
Is this still an issue? Does this need a PR to implement?
This sounds like a duplicate of #165, fixed in #184.
@JimmyBoh @stuartpb Can you repro this? If so, I'll just make a new <a> element for each click event. As you said though, this seems like it should be fixed from #184.
I think my actual issue was regarding the browser blocking any downloads after the initial. Our solution was to just update the security settings of our browsers to allow our site to download multiple files. We are pretty close to release so I don't know if we will upgrade to the latest version, but I can try it locally after the weekend.
I'm having the same issue with Chrome 65. Here is a snippet that reproduces the problem:
import { saveAs } from 'file-saver'
for(const index of [ ...Array(5).keys() ]) {
console.log(index)
var blob = new Blob(["Hello world!"], {type: "text/plain;charset=utf-8"});
saveAs(blob, `hello-world-${index}.txt`);
}
This snippet only downloads the last file, hello-world-4.txt.
Here is a repl.it to try it: https://repl.it/@PelleJacobs/SaveAsMultipleFiles
Does saveAs use promises?
Does saveAs use promises?
No. The task is not async. Even doe the writing to the hard drive is async, we have no way of knowing when it has finish writing.
same issue here... any updates, please?
I am still getting this error. Is there any workaround for this?
@leondroidgeeks We use the following workaround
It's not perfect, but it works for us.
download = async () => {
for(const index of [ ...Array(5).keys() ]) {
console.log(index)
var blob = new Blob(["Hello world!"], {type: "text/plain;charset=utf-8"})
saveAs(blob, `hello-world-${index}.txt`)
await new Promise(setTimeout)
}
}
@pellejacobs it's tricky! thanks
PS: I've added a slight modification to your snippet.
await new Promise(r => setTimeout(r, 1000));
Most helpful comment
I'm having the same issue with Chrome 65. Here is a snippet that reproduces the problem:
This snippet only downloads the last file,
hello-world-4.txt.Here is a repl.it to try it: https://repl.it/@PelleJacobs/SaveAsMultipleFiles