ekalchev
ekalchev

Reputation: 972

How to upload file with CEF?

I am using CefSharp but the question applies also for CEF C++

I have javascript application that you can use to edit/transform images. After you are done you want to upload the image to CEF and save it in database/filesystem.

Javascript code uploads the file using FormData API as multipart/form-data. I have custom ResourceHandler which is handling the request and trying to read the post data.

However in

bool ProcessRequest(IRequest request, ICallback callback)

request.PostData.HasExcludedElements == true

and file binary data is missing. I found those posts

https://www.magpcss.org/ceforum/viewtopic.php?f=6&t=16625 https://magpcss.org/ceforum/viewtopic.php?f=6&t=14371

which describes the same problem. It seems this is not supported by CEF, however there is no workaround how to upload binary file.

How I am supposed to upload binary data (Blob) from Javascript to CEF?

Upvotes: 3

Views: 1354

Answers (1)

Dave S
Dave S

Reputation: 1502

You can make an AJAX request to a fake URL like http://grab-this-image.com/grabme.htm?savas=filename and intercept it in (C++) ClientHandler::OnBeforeResourceLoad()

Grab the data then return RV_CANCEL to cancel the navigation.

Upvotes: 1

Related Questions