Download files to custom location

Post Reply
padamjain
Posts: 23
Joined: Thu Jan 17, 2019 12:36 pm

Download files to custom location

Post by padamjain »

Hi,

I am using CEF binaries 86.0.23 and FMXBrowser component.
one of the web page is trying to save csv file on the disk by opening a save as dialog box.

I have implemented below in my form :

procedure TMainForm.FMXChromium1BeforeDownload(Sender: TObject; const browser: ICefBrowser;
const downloadItem: ICefDownloadItem; const suggestedName: ustring;
const callback: ICefBeforeDownloadCallback);
var
S: string;
begin
S := ExtractFilePath(ParamStr(0));
callback.cont(S + suggestedName, false);
end;

But, It is always saving file in the exe path, its not showing that popup which asks user to select location to save file.

Any advises ?

Thanks.
User avatar
salvadordf
Posts: 2822
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Download files to custom location

Post by salvadordf »

Hi,

Read these pages for more information about the TChromium events related to the fli downloads :
https://magpcss.org/ceforum/apidocs3/projects/(default)/CefDownloadHandler.html
https://magpcss.org/ceforum/apidocs3/projects/(default)/CefDownloadItem.html
https://magpcss.org/ceforum/apidocs3/projects/(default)/CefDownloadItemCallback.html

You will have to execute the "callback" parameter found in the TChromium.OnBeforeDownload event asynchronously after you show your custom "Save as..." dialog.

Remember that the TChromium.OnBeforeDownload event is executed in a CEF thread and VCL is not thread safe. You will have to save all the parameters in fields or variables, then send a message to the form to show the "Save as..." diaglog in the main application thread.

Set all the saved interfaces to NIL after you use them or you will have shutdown issues.
Post Reply