7

I'm trying to create an extension which downloads multiple files at once.

In order to accomplish that, I'm using chrome downloads api, here is the code (with AngularJS):

var fileDownloadProperties = function(raw) {
    return {
      url: "https:" + raw.url,
      filename: sharedDir + "/" + raw.name + "pdf",
      saveAs: false
    }
};
$scope.status = "";
filesToDownload.forEach(function (raw) {
  chrome.downloads.download(fileDownloadProperties(raw));
});

The problem is that when the script runs it ignores the saveAs option, and proceed with opening the save as dialog (the name and location are passed correctly, as they are the defaults in the dialog, but could be overwritten).

While it does allow me to download, it's not very useful as I can have over tens of files (and the next save dialog will open only when the previous file finished downloading!).

Is there a way to force chrome to download files silently and simultaneously? I tried other solutions (like the code below), but none seems to avoid the dialog from opening.

var a = document.createElement("a");
a.href = files[0];
a.download = files[0];
a.click();  

Any help will be greatly appreciated, thanks.

Nadav96
  • 1,274
  • 1
  • 17
  • 30
  • 1
    I don't believe it's possible. I certainly wouldn't use Chrome again if I found it had downloaded files in an unsolicited manner, even more so if it did it silently. Can you not create a zip file on the server and download that instead? At least it's only 1 download. – Reinstate Monica Cellio Dec 30 '16 at 17:18
  • @Archer So what is the purpose of the saveAs option? It is stated in [docs](https://developer.chrome.com/extensions/downloads#method-download) that if set, the saveAs will "Use a file-chooser to allow the user to select a filename". – Nadav96 Dec 30 '16 at 17:23
  • From the documentation it sounds like saveAs is the opposite of what you want. What happens if you just supply a filename? – Reinstate Monica Cellio Dec 30 '16 at 17:29
  • @Archer unfortunately it still opens the dialog... And I didn't meant completely silent, rather that the files will download without opening the dialog every time (and saved to the Downloads folder), it must be possible, seems to me like a basic functionality. – Nadav96 Dec 30 '16 at 17:33
  • Okay - that makes more sense. Can you possible consider making a zip file on the server, upon request of several files? – Reinstate Monica Cellio Dec 30 '16 at 17:35
  • @Archer I thought about it, have you heard about already built API that does that (zipping)? I rather not set up a server myself, way out of scope haha. – Nadav96 Dec 30 '16 at 17:38
  • See [How to download, zip and save multiple files with Javascript and get progress?](http://stackoverflow.com/questions/17274655/how-to-download-zip-and-save-multiple-files-with-javascript-and-get-progress?rq=1), [Multiple download links to one zip file before download javascript](http://stackoverflow.com/questions/37176397/multiple-download-links-to-one-zip-file-before-download-javascript/) – guest271314 Dec 30 '16 at 17:39
  • You're unlikely to find an API to do this, as it would mean downloading every file to the API endpoint in order to zip them and download them as 1 file. – Reinstate Monica Cellio Dec 30 '16 at 17:40
  • @Archer Maybe just send the url's to the API in the payload, and it will download it by itself? Starting to sound like a solid idea haha ;) – Nadav96 Dec 30 '16 at 17:42
  • Know bug: https://crbug.com/417112 – Daniel Herr Dec 30 '16 at 19:12

2 Answers2

4

You can instruct your user to set Chrome settings to have

Ask where to save each file before downloading

"Save As" turned on/off.

https://lifehacker.com/make-chrome-ask-where-to-save-downloaded-files-by-chang-1790840372

Jenna Leaf
  • 2,255
  • 21
  • 29
2

The answer provided by Jenna is an acceptable workaround, however, forcing users to change their preferences is not something I will take as an "Accepted solution". There is an issue filed for this bug on this thread.

I guess the only possible way of having a correct fix is for the chrome team to stand up and fix this issue for us developers. I would recommend to put more pressure on the thread by adding a comment indicating why you need this to be fixed and how urgent it is. Also and most important, make sure you click the star to have the issues starred as they will pay more attention to it.

enter image description here

Morfinismo
  • 4,985
  • 4
  • 19
  • 36