Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your code is close. You are only sending your file field but not your text fields. To do all three, try this instead:</p> <pre><code>function HttpPostFile(const URL, InputText1FieldName, InputText1, InputText2FieldName, InputText2, InputFileFieldName, InputFileName: string; InputFileData: TStream; ResultData: TStrings): Boolean; var HTTP: THTTPSend; Bound: string; begin Bound := IntToHex(Random(MaxInt), 8) + '_Synapse_boundary'; HTTP := THTTPSend.Create; try WriteStrToStream(HTTP.Document, '--' + Bound + CRLF + 'Content-Disposition: form-data; name=' + AnsiQuotedStr(InputText1FieldName, '"') + CRLF + 'Content-Type: text/plain' + CRLF + CRLF); WriteStrToStream(HTTP.Document, InputText1); WriteStrToStream(HTTP.Document, CRLF + '--' + Bound + CRLF + 'Content-Disposition: form-data; name=' + AnsiQuotedStr(InputText2FieldName, '"') + CRLF + 'Content-Type: text/plain' + CRLF + CRLF); WriteStrToStream(HTTP.Document, InputText2); WriteStrToStream(HTTP.Document, CRLF + '--' + Bound + CRLF + 'Content-Disposition: form-data; name=' + AnsiQuotedStr(InputFileFieldName, '"') + ';' + CRLF + #9'filename=' + AnsiQuotedStr(InputFileName, '"') + CRLF + 'Content-Type: application/octet-string' + CRLF + CRLF); HTTP.Document.CopyFrom(InputFileData, 0); WriteStrToStream(HTTP.Document, CRLF + '--' + Bound + '--' + CRLF); 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>If you switch to Indy, you can use its <code>TIdMultipartFormDataStream</code> class:</p> <pre><code>function HttpPostFile(const URL, InputText1FieldName, InputText1, InputText2FieldName, InputText2, InputFileFieldName, InputFileName: string; InputFileData: TStream; ResultData: TStrings): Boolean; var HTTP: TIdHTTP; Input: TIdMultipartFormDataStream; Output: TMemoryStream; begin Result := False; try Output := TMemoryStream.Create; try HTTP := TIdHTTP.Create; try Input := TIdMultipartFormDataStream.Create; try Input.AddFormField(InputText1FieldName, InputText1); Input.AddFormField(InputText2FieldName, InputText2); Input.AddFormField(InputFileFieldName, 'application/octet-stream', '', InputFileData, InputFileName); HTTP.Post(URL, Input, Output); finally Input.Free; end; finally HTTP.Free; end; Output.Position := 0; ResultData.LoadFromStream(Output); Result := True; finally Output.Free; end; except end; end; </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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