how to do a file upload with synapse to a url? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- billyb123 · 2018-02-14 02:34 so I need to upload a file using synapse. I also need to add certain headers to my http post request. It seems my brain has melted,  I know about HttpPostFile, but I cant add headers to that method? Basically, my question is (1) how to add headers to HttpPostFile method? or (2) is there a synapse way to simply add file upload to httpmethod method? Sorry if its a silly question, its 3AM here, my brain has stopped working hours ago. Code: [Select]{$mode delphi} uses sysutils, strutils, httpsend, classes, ssl_openssl, synautil; var   http: thttpsend; begin   http := thttpsend.create;   http.headers.add('SOME AUTH HEADER');   http.headers.add('ANOTHER AUTH HEADER');   http.headers.add('Content-Type: application/octet-string');   (* is there a way to simply "add file to upload" without manually editing http request? *)   http.free; end. ---------------------------------------------------------------------- Thaddy · 2018-02-14 08:05 http://synapse.ararat.cz/doc/help/ Look at HttpPostBinary or HttpPostFile That may be just what you need. ---------------------------------------------------------------------- Leledumbo · 2018-02-15 17:16 Looking at THTTPSend documentation, it only provides generic Document property, no easy file upload mechanism, you must build the body manually. If you must use Synapse, I don't think you have any other choice. ---------------------------------------------------------------------- rvk · 2018-02-15 17:27 Quote from: Leledumbo on February 15, 2018, 06:16:05 pmLooking at THTTPSend documentation, it only provides generic Document property, no easy file upload mechanism, you must build the body manually. If you must use Synapse, I don't think you have any other choice. Like Thaddy already mentioned, there are functions HttpPostFile() and HttpPostBinary() which already do that work. So there is no need to build the body manually. The only thing is, if you want to add headers you need to copy that function and do the adding yourself. But that's just a copy/paste and adding a line like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i HTTP.Headers.Add('Header: content'); For example, this is the HttpPostFile of Synapse of which you can make a copy: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function HttpPostFile(const URL, FieldName, FileName: string;  const Data: TStream; const ResultData: TStrings): Boolean;var  HTTP: THTTPSend;  Bound, s: string;begin  Bound := IntToHex(Random(MaxInt), 8) + '_Synapse_boundary';  HTTP := THTTPSend.Create;  try    s := '--' + Bound + CRLF;    s := s + 'content-disposition: form-data; name="' + FieldName + '";';    s := s + ' filename="' + FileName +'"' + CRLF;  s := s + 'Content-Type: Application/octet-string' + CRLF + CRLF;    WriteStrToStream(HTTP.Document, s);    HTTP.Document.CopyFrom(Data, 0);    s := CRLF + '--' + Bound + '--' + CRLF;    WriteStrToStream(HTTP.Document, s);    HTTP.MimeType := 'multipart/form-data; boundary=' + Bound;    HTTP.Headers.Add('Header: content');    Result := HTTP.HTTPMethod('POST', URL);    if Result then      ResultData.LoadFromStream(HTTP.Document);  finally    HTTP.Free;  end;end;So adding a header in there shouldn't be that difficult (I highlighted the line). ---------------------------------------------------------------------- billyb123 · 2018-02-19 16:41 thanks guys