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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.
Good afternoon. Please tell me whether it is possible to add an array of TBytes to the POST request. The bottom line is, under certain conditions, the program takes a picture of its window, which is encoded in the webp format and as a result we get the TBytes array. This array must be transferred to the server in a specific request. I catch this request in the onBeforeResourceLoad event:
var Screen: TBytes //global variable
//..
procedure onBeforeResourceLoad(...)
begin
//...
if [some condition] then
begin
request.Method := 'POST';
request.SetHeaderByName('Content-Type','application/x-www-form-urlencoded',true);
if not Assigned(request.PostData) then
request.PostData := TCefPostDataRef.New;
request.PostData.AddElement(CreateField('url=' + ReportData.CurrentURL));
//insert TBytes here "Screen"
end;
end;
Can I add a Screen variable here in PostData? And can this be done without saving Screen to a file?
Thanks for the help.
I apologize, but could you explain in more detail? In the examples, a string is used, the parameters are formed by one string with the substitution of the parameter name. But what about the flow, I do not quite understand. You mean you need to convert the TBytes array to a string and then add it to the post parameters?
Sorry if this is a stupid question, but something I can’t understand what to do
You need to know the server API details and send the data as the server wants.
For example, sometimes you may have to send the binary data in a POST request with a key-value pair. That value is usually encoded in base64.
The example in the URLRequest demo sends simple strings in key-value pairs but you can send anything conveniently encoded.
In order to encode or decode values you can use the functions available in Delphi, Indy, CEF4Delphi, etc.
Search "delphi encode image to base64" and you will find many code examples.