Does sparkle support multipart/form-data

Hi,
Just wondering .. does sparkle support multipart/form-data. With delphi 10.3.1 thttpclient has issue with wrongly generated boundary (extra -- in first part9 and Indy drives me crazy with encoding problems.

Server-side, yes, it can receive multipart data. Client side, you would have to build the multipart content your self, and then send as bytes.

Dear Wagner, can you please give an example of how we can build the client side multipart content and to add it to request ?
Thank you in advance!

You can use this code to generate a multipart/form-data content in a byte array:

var
  Data: TMultipartFormData;
  Content: TBytes;
  Request: THttpRequest;
begin
  Data := TMultipartFormData.Create;
  try
    Data.AddField('text1', 'This is a text');
    Data.AddField('text2', 'This is a text');
    Data.AddFile('myfile', 'C:\temp\myfile.pdf');

    SetLength(Content, Data.Stream.Size);
    Data.Stream.Position := 0;
    Data.Stream.Read(Content[0], Length(Content));
  finally
    Data.Free;
  end;
end;

Then you can simply set the Content to the request body:

    Request.SetContent(Content);
2 Likes

Thank you Wagner!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.