Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downloading multiple files at once #331

Closed
odflash opened this issue May 9, 2017 · 11 comments
Closed

Downloading multiple files at once #331

odflash opened this issue May 9, 2017 · 11 comments

Comments

@odflash
Copy link

odflash commented May 9, 2017

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.

@jimbuck
Copy link

jimbuck commented Nov 21, 2017

Is this still an issue? Does this need a PR to implement?

@stuartpb
Copy link

stuartpb commented Jan 4, 2018

This sounds like a duplicate of #165, fixed in #184.

@eligrey
Copy link
Owner

eligrey commented Jan 6, 2018

@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.

@jimbuck
Copy link

jimbuck commented Jan 6, 2018

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.

@pellejacobs
Copy link

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

@DanielRuf
Copy link

Does saveAs use promises?

@jimmywarting
Copy link
Collaborator

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.

@tarim
Copy link

tarim commented Jul 20, 2018

same issue here... any updates, please?

@leondroidgeeks
Copy link

I am still getting this error. Is there any workaround for this?

@pellejacobs
Copy link

@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) 
  }
}

@SuperStar518
Copy link

SuperStar518 commented May 7, 2019

@pellejacobs it's tricky! thanks
PS: I've added a slight modification to your snippet.

await new Promise(r => setTimeout(r, 1000)); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants