Page 1 of 2

Downloading multiple Files

PostPosted: Tue Jun 29, 2021 6:12 am
by vinayk
Hi Everyone,

I am trying to download multiple files simultaneously by creating downloadable links pointing to blobs and clicking on the links. I am trying to do something similar to the following code.

Code: Select all
for (let i = 0; i < 10; i++) {
    let blobFile = new Blob(["file"+i])
    var link = document.createElement('a');
    link.href = URL.createObjectURL(blobFile)
    link.download = 'Download.txt';
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
}


When i try this in chrome, chrome is showing 10 separate save as dialogs and is downloading multiple files.
When i try the same in CEF (using CEF client app), it is only downloading one file. (shows only one save as dialogs).

Do we need to do any additional handling for supporting download of multiple files? Please let me know if i'm missing something here.

I am using 88.0.4324.182 version of CEF.

Thanks in Advance.

Re: Downloading multiple Files

PostPosted: Tue Jun 29, 2021 9:24 am
by magreenblatt
Is chrome showing 10 separate save as dialogs at the same time? If so, that sounds like a bug.

In CEF you can use CefDownloadHandler to handle/manage downloads.

Re: Downloading multiple Files

PostPosted: Tue Jun 29, 2021 9:37 am
by vinayk
Hi Marshall,

Thanks for checking this.

I'm using CEFDownloadHandler for managing downloads, where in we are calling the continue callback when we receive the OnBeforeDownload call with downloadPath and saveAs (true) as params. But in this case, download is not being completed for other files (only one file is being downloaded).

Also, from what i understand, for the previous posted code, chrome and CEF are expected to show multiple save as dialogs right? as user is trying to download multiple files. (for each file, one picker will be shown for saving).

In Chrome, when we try to download multiple files, a popup is shown asking user whether to allow download of multiple files or not? If user selects yes, chrome shows multiple save as dialogs and downloads all files else downloads are being blocked. Is there any setting/flag in CEF which needs to passed/turned on for getting this behaviour (where user can download multiple files at a time).

Re: Downloading multiple Files

PostPosted: Tue Jun 29, 2021 9:59 am
by magreenblatt
The default CEF save as dialog implementation only supports one dialog at a time. If you pass show_dialog=false to CefBeforeDownloadCallback::Continue then it should allow multiple simultaneous downloads.

You might also consider using the Chrome runtime if you want the same UX behavior as Chrome.

Re: Downloading multiple Files

PostPosted: Tue Jun 29, 2021 10:42 am
by vinayk
Thanks Marshall,

just to confirm my understanding, so, In CEF, when a save as dialog is open, all the subsequent downloads (which try to show save as dialog) will be discarded .

Also, I went through the code, it looks the RunFileChooser method is returning empty file list (https://bitbucket.org/chromiumembedded/ ... #lines-241) if a file chooser is already pending.

And because of this, download is being cancelled (https://bitbucket.org/chromiumembedded/ ... #lines-172)

So the only way to support multiple simultaneous downloads would be to pass show_dialog=false to CefBeforeDownloadCallback::Continue right?

Also, i tried to use chromium runtime (by passing --use-views --enable-chrome-runtime to cef client), but still CEF is still this behaviour only (not showing multiple dialogs as chrome)

Re: Downloading multiple Files

PostPosted: Tue Jun 29, 2021 12:05 pm
by magreenblatt
So the only way to support multiple simultaneous downloads would be to pass show_dialog=false to CefBeforeDownloadCallback::Continue right?

I believe so, yes. Note that I have not personally tested this with current CEF versions.

Also, i tried to use chromium runtime (by passing --use-views --enable-chrome-runtime to cef client), but still CEF is still this behaviour only (not showing multiple dialogs as chrome)

Interesting. It may depend on more of the Chrome UI. You can try "cefsimple --enable-chrome-runtime" to get a fully styled Chrome window.

Re: Downloading multiple Files

PostPosted: Tue Jun 29, 2021 12:38 pm
by vinayk
Marshall,

I have verified it on windows cef client app, CEF iss showing multiple save as dialogs for downloading (after dismissing a dialog, it is showing the next dialog). So here, i was able to download multiple files simultaneously.

But on mac, this is not the case. (only one dialog is shown).

I'm not able to understand the behaviour properly, If the workflow is working fine on windows, shouldn't it be same on mac? Can you please help me

Re: Downloading multiple Files

PostPosted: Tue Jun 29, 2021 12:45 pm
by magreenblatt
What, specifically, are you comparing on Windows and Mac? Does multiple download work in Chrome on Mac? What about CEF with Chrome runtime on Mac?

Re: Downloading multiple Files

PostPosted: Tue Jun 29, 2021 12:58 pm
by vinayk
magreenblatt wrote:What, specifically, are you comparing on Windows and Mac? Does multiple download work in Chrome on Mac? What about CEF with Chrome runtime on Mac?


Marshall, sorry for not mentioning clearly.

This is w.r.t to CEF only.
I'm comparing the default CEF on Windows and Mac. Multiple download works fine in windows.(when i have tried below code, i am observing 10 save as dialogs and files were downloaded ).

whereas on mac, only one dialog is shown and one file is downloaded. (this is w.r.t default CEF with no runtime).

In case of chrome, even on mac, multiple download works fine.

Re: Downloading multiple Files

PostPosted: Tue Jun 29, 2021 1:59 pm
by magreenblatt
Could be a bug in the CEF implementation on Mac. If the problem reproduces with a supported version then you’re welcome to add an issue in the tracker and/or try to debug the problem yourself and submit a PR.