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.

How to use TCEFUrlRequestClientComponent to upload file?

Post Reply
tad.chen
Posts: 104
Joined: Fri Jan 04, 2019 1:39 am

How to use TCEFUrlRequestClientComponent to upload file?

Post 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.
User avatar
salvadordf
Posts: 4056
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to use TCEFUrlRequestClientComponent to upload file?

Post 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
tad.chen
Posts: 104
Joined: Fri Jan 04, 2019 1:39 am

Re: How to use TCEFUrlRequestClientComponent to upload file?

Post 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?
User avatar
salvadordf
Posts: 4056
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to use TCEFUrlRequestClientComponent to upload file?

Post by salvadordf »

The DevTools require an initialized web browser with a TChromium or TFMXChromium component.
Post Reply