Downloading file from XHR(URL with authentication headers)

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Downloading file from XHR(URL with authentication headers)

Postby vinayk » Thu Feb 13, 2020 8:01 am

Hello. I am trying to implement downloading in CEF
What I am trying to achieve is: how to let CEF handle the download when a fetch request/XHR request is made in JS.
I tried downloading the entire file in JS and create an ObjectUrl and clicking on it will call download handler of CEF and it shows the file picker and writes to file from memory but the problem is memory bumpup in case of huge files. I would ideally want CEF to download files when a fetch/XHR request is made(there are some authentication headers). What is the ideal way to do this in CEF and please point me in that direction. Also is it possible to show an open file dialog for multiple downloads and let CEF handle the downloading and multiple files with same name cases? I can't find any way to do this. What I understand is we need to show separate save-as dialogs for all the files downloaded as a group. Can we do any better than this??

Thanks in advance.
vinayk
Techie
 
Posts: 12
Joined: Thu Feb 13, 2020 7:46 am

Re: Downloading file from XHR(URL with authentication header

Postby magreenblatt » Thu Feb 13, 2020 4:09 pm

Why do you want to download fetch/XHR requests specifically? If your intention is to view these requests you might want to use the DevTools Network tab instead.

You can also implement your own download manager logic by using CefDownloadHandler.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Downloading file from XHR(URL with authentication header

Postby vinayk » Fri Feb 14, 2020 1:06 am

I have to download a file from a server. We have to pass authentication headers along with the request.
So we can't click on the URL and ask CEF to download it.
I implemented download manager but I am not able to pass headers along with the request.
Is there any way to use the download manager?? Please correct me if I'm wrong, the Download manager can be invoked by pressing on a link right? Or is there any other way to invoke it from js.
Also is there any way to save a streaming response to stream writer in CEF??
Thanks
vinayk
Techie
 
Posts: 12
Joined: Thu Feb 13, 2020 7:46 am

Re: Downloading file from XHR(URL with authentication header

Postby amaitland » Fri Feb 14, 2020 2:03 am

Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Re: Downloading file from XHR(URL with authentication header

Postby vinayk » Fri Feb 14, 2020 2:14 am

Thanks, amaitland.
But the Start download function will download from an URL string but how do I pass authentication headers along with it??
vinayk
Techie
 
Posts: 12
Joined: Thu Feb 13, 2020 7:46 am

Re: Downloading file from XHR(URL with authentication header

Postby amaitland » Fri Feb 14, 2020 4:50 am

Actually doesn't look like StartDownload is triggering any of the CefRequestHandler methods, so scrap that idea.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

Re: Downloading file from XHR(URL with authentication header

Postby magreenblatt » Fri Feb 14, 2020 10:32 am

You should be able to add the authentication headers in CefResourceRequestHandler::OnBeforeResourceLoad after clicking the link or calling StartDownload. If you want the file contents as a stream use CefURLRequest.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Downloading file from XHR(URL with authentication header

Postby meldefern » Wed Mar 11, 2020 12:27 pm

Are you adding the
Code: Select all
content-disposition
header to your server response?
meldefern
Newbie
 
Posts: 1
Joined: Wed Mar 11, 2020 12:21 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 47 guests