Page 1 of 1

How to use TCEFUrlRequestClientComponent to upload file?

Posted: Sat May 13, 2023 3:31 am
by tad.chen
I want to upload file to a PHP server. So I modified URLRequest Demo code by changing SetToBytes to SetToFile in CreatePOSTRequest function.

Then I click "Send POST request" button, it shows 'Parameters sent!'. But The server didn't receive the file.

Html code can upload the file sucessfully.
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
Maybe enctype in html is important, But I don't know how to set it in CreatePOSTRequest.

Re: How to use TCEFUrlRequestClientComponent to upload file?

Posted: Sat May 13, 2023 2:58 pm
by salvadordf
Hi,

I've never used that component to upload a file but it should be possible.
I would recommend to use a local web server while you implement this feature because the server logs will have many clues.

Encoding the file correctly is very important. Search "delphi indy http post upload file" to know more details.

Perhaps you can use some Indy components to encode the file.
https://stackoverflow.com/questions/10765661/http-post-with-indy
https://stackoverflow.com/questions/18522286/post-a-file-through-https-using-indy-delphi-components

Re: How to use TCEFUrlRequestClientComponent to upload file?

Posted: Mon May 15, 2023 2:36 pm
by tad.chen
Thank you for your information!

Now, it works! But a little difficult to debug. Can TCEFUrlRequestClientComponent open DevTools to see the response content from the server?

Re: How to use TCEFUrlRequestClientComponent to upload file?

Posted: Mon May 15, 2023 8:01 pm
by salvadordf
The DevTools require an initialized web browser with a TChromium or TFMXChromium component.