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

multiple simultaneous downloads possible ? #66

Open
mafar opened this issue Jul 5, 2018 · 6 comments
Open

multiple simultaneous downloads possible ? #66

mafar opened this issue Jul 5, 2018 · 6 comments

Comments

@mafar
Copy link

mafar commented Jul 5, 2018

It is mentioned in docs that in download function , url is string
download(BrowserWindow.getFocusedWindow(), args.url)

Is there a way to download a given array of files simultaneously ? and have one promise/callback for all

Can anyone help with promise chain to achieve this ?
I asked the question here stackoverflow
Can someone suggest fix for the code ?

@mafar
Copy link
Author

mafar commented Jul 5, 2018

electron-dl-multi.zip
Sample zip

@itzsaga
Copy link

itzsaga commented Jul 25, 2018

We implemented downloading an array of file objects like this and it works for us. Hopefully, you can garner how to extract what you need from this.

ipcMain.on("download-files", async (event, files) => {
  const downloadLocation = app.getPath("userData");

  const promises = files.map(file =>
    download(mainWindow, file.url, {
      saveAs: false,
      directory: downloadLocation,
      onProgress: progress => {
        event.sender.send("download-progress", { progress, file });
      }
    })
  );

  await Promise.all(promises);
});

@iwuvjhdva
Copy link

The code above doesn't work for me, the promises get resolved immediately. Reducing files array to a single item and reusing the same code works perfectly.

@MiroFurtado
Copy link

MiroFurtado commented Jan 3, 2019

Frustrating that the tip right above me is necessary. These promises shouldn't be getting resolved immediately!

Might submit a pull if I get around to it

@joshuapinter
Copy link
Contributor

Frustrating that the tip right above me is necessary. These promises shouldn't be getting resolved immediately!

Might submit a pull if I get around to it

Got bit by the same thing. Did you ever get around to submitting that Pull Request?

@theogravity
Copy link
Contributor

I wrote a library that handles multiple downloads and fixes a lot of issues around using a save as dialog:

https://github.com/theogravity/electron-dl-manager

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

6 participants