Hello.
How can I send request with multipart/form-data with image file?
For example:
Content-Disposition: form-data; name="model"
news_image
Content-Disposition: form-data; name="img"; filename="1.jpg"
Content-Type: image/jpeg
P.S. Or probably is it possible like in Selenium - SendKeys to element with full file name?
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.
Post request with MultiPart
- salvadordf
- Posts: 4580
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Post request with MultiPart
Hi,
You should be able to do both things.
You can create a custom POST request using the code in the URLRequest demo. You would have to encode the image file and call TCefPostDataElementRef.SetToBytes. You may also have to add a "content-type" header to the request.
Alternatively, you can also emulate keyboard and mouse events to make the browser send the file for you. You can use a browser in OSR mode to log all the mouse and keyboard events, and replicate them later. Use the SimpleOSRBrowser demo for that.
You should be able to do both things.
You can create a custom POST request using the code in the URLRequest demo. You would have to encode the image file and call TCefPostDataElementRef.SetToBytes. You may also have to add a "content-type" header to the request.
Alternatively, you can also emulate keyboard and mouse events to make the browser send the file for you. You can use a browser in OSR mode to log all the mouse and keyboard events, and replicate them later. Use the SimpleOSRBrowser demo for that.
Re: Post request with MultiPart
Ok. Thank you.
Re: Post request with MultiPart
Hi. Faced the same problem, unable to send multipart/form-data request. I don’t understand how to make the request body as follows:
How to insert the title is clear, but how the request forms the body, I cannot understand. I tried to do it as described in the URLRequest demo, but the server does not accept such a request. And in this demo, it is not clear how the same boundary is formed and where it is inserted. I need to send a file to the server in the body of a multipart/form-data request, but unfortunately nothing works. Could you explain in more detail how this can be done. Thank you in advance.
Code: Select all
Header
...
Content-Type: multipart/form-data; boundary=---------------573cf973d5228--
...
Body
---------------573cf973d5228
Content-Disposition: form-data; name="upload"
Загрузить
---------------573cf973d5228
Content-Disposition: form-data; name="myfile"; filename="my_file_name.jpg"
Content-Type: image/jpeg
Content file
---------------573cf973d5228--
- salvadordf
- Posts: 4580
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Post request with MultiPart
I've never done that but I can give you the links to the information that might help you.
The URLRequest demo uses these CEF classes to send the POST request :
https://www.magpcss.org/ceforum/viewtopic.php?f=6&t=396
The URLRequest demo uses these CEF classes to send the POST request :
- TCefRequestRef : https://magpcss.org/ceforum/apidocs3/projects/(default)/CefRequest.html
- TCefPostDataRef : https://magpcss.org/ceforum/apidocs3/projects/(default)/CefPostData.html
- TCefPostDataElementRef : https://magpcss.org/ceforum/apidocs3/projects/(default)/CefPostDataElement.html
https://www.magpcss.org/ceforum/viewtopic.php?f=6&t=396
Re: Post request with MultiPart
OK, thanks for the info.