Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

Cancel download in TChromium.OnBeforeDownload

Post Reply
michal@dorfin.waw.pl
Posts: 41
Joined: Sun Feb 05, 2017 8:53 am

Cancel download in TChromium.OnBeforeDownload

Post by michal@dorfin.waw.pl »

Hi,

I'm trying to do the "multiple file download" like in Chrome. When user click several download links - I wish to show the progress of every file being downloaded in the same time.
I want to use TCEFUrlRequestClientComponent - create it for every file that is being clicked and then lisntening to allevents that are needed to complete the download.
Question one: is there a better solution of doing this ? Maybe TChromium has built in engine to do this automatically. Now in my case when I start the next file download - the current one is "canceled" (which is showed in DevTools). Is there any option to enable multiple downloads ?

My plan was to initiate the TCEFUrlRequestClientComponent in "TChromium.OnBeforeDownload", where I have all needed information: url , suggestedFilename. I want to cancel the default "download" and start the UrlRequest download.
My solution has one problem. In TChromium.OnBeforeDownload I can't "cancel" the download.
The parameter: callback: ICefBeforeDownloadCallback
has not any method called "cancel".
User avatar
salvadordf
Posts: 4052
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Cancel download in TChromium.OnBeforeDownload

Post by salvadordf »

michal@dorfin.waw.pl wrote: Fri Mar 27, 2020 5:32 pm Hi,

I'm trying to do the "multiple file download" like in Chrome. When user click several download links - I wish to show the progress of every file being downloaded in the same time.
I want to use TCEFUrlRequestClientComponent - create it for every file that is being clicked and then lisntening to allevents that are needed to complete the download.
Question one: is there a better solution of doing this ? Maybe TChromium has built in engine to do this automatically. Now in my case when I start the next file download - the current one is "canceled" (which is showed in DevTools). Is there any option to enable multiple downloads ?
BriskBard does exactly that and it works correctly. It calls TChromium.StartDownload and it can download several files at the same time.
michal@dorfin.waw.pl wrote: Fri Mar 27, 2020 5:32 pm My plan was to initiate the TCEFUrlRequestClientComponent in "TChromium.OnBeforeDownload", where I have all needed information: url , suggestedFilename. I want to cancel the default "download" and start the UrlRequest download.
My solution has one problem. In TChromium.OnBeforeDownload I can't "cancel" the download.
The parameter: callback: ICefBeforeDownloadCallback
has not any method called "cancel".
That's also a good solution. You can cancel it using callback.cancel in TChromium.OnDownloadUpdated
michal@dorfin.waw.pl
Posts: 41
Joined: Sun Feb 05, 2017 8:53 am

Re: Cancel download in TChromium.OnBeforeDownload

Post by michal@dorfin.waw.pl »

Thank You for Your explanation. You are right- multiple downloads work fine without extra effort.
But I found another problem.
When there is <a> link on website - the downloadItem.url shows proper download url.
But when the website has a button that fires request to the server and that request returns a file to download (not the url to resource!) - the "downloadItem.url" shows the url of current page.
Here is an explanation and example:
There is a "button" that fires the GET request to the server.
screen1.png
When user click it there is a request that has in response PDF file.
screen2.png
In Chromium in this case when the download begins - there is a OnBeforeDownload event fired.
And it the downloadItem.url there is the website url - not the request.
Is there any possibility to get the request url inside the OnBeforeDownload event ?
I know that I can inspect the request and response but in this case how would I know that request is for the resource that will be downloaded not rendered ?
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4052
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Cancel download in TChromium.OnBeforeDownload

Post by salvadordf »

Some sites generate the downloaded resources dynamically and the only URL that can be used to download that resource is the one you already have.

If that's the case, it's not possible to get a direct resource URL because the file doesn't exist in the server. You can only use the value in "downloadItem.url".
Post Reply