Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to send a file AND other POST data with Synapse
    primarykey
    data
    text
    <p><strong>Delphi used:</strong> 2007.</p> <p>Hello,</p> <p>I have a simple web page with two text input and one file input. Now, for the form to be sent, both the text inputs and the file input have to be filled. With Synapse, I know how to upload a file (<em>HttpPostFile</em>) and how to post data (<em>HttpMethod</em>). However, I don't know how to do both.</p> <p>After looking at the source code of Synapse, I guess I have to "format" my data with boundaries or something like that. I guess I should have one boundary for my input file and another boundary for my text inputs. I found an article on the subject, but it's about sending email attachments. I tried to reproduce what they said with Synapse, with no results.</p> <p>Code for <em>HttpPostFile</em>:</p> <pre><code>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; Result := HTTP.HTTPMethod('POST', URL); if Result then ResultData.LoadFromStream(HTTP.Document); finally HTTP.Free; end; end; </code></pre> <p>Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload