http UploadByFieldNames method
Return to Introduction  Previous page  Next page
Applies to
WinHTTP component.  

function UploadByFieldNames(const FieldNames: Array of String): Boolean; // returns False if busy  

The UploadByFieldNames, like the Upload method starts HTTP request to upload data via HTTP protocol, using multipart/form-data POST method, introduced in RFC 1867.  
tip However, unlike, the Upload method, the UploadByFiles allows to specify the field names as parameters, so in the OnUploadFieldRequest event you just need to write the data to UploadStream (data proper to each FieldName), without requiring to specify the FieldName's.  
Before starting the uploading, it requests fields which should be uploaded using OnUploadFieldRequest event. To specify number of fields which should be uploaded — pass it in NumberOfFields parameter (this specifies how many times the OnUploadFieldRequest should be triggered to request another piece of data).  
After requesting the data required to build HTTP request, it starts it with multipart/form-data Content Type in the HTTP header and constantly trigger OnUploadProgress event after each data block with size specified in TransferBufferSize property.  

procedure TForm1.UploadBtnClick(Sender: TObject);  
  WinHTTP1.Upload(['']); // upload 2 files  
{ To specify the data which should uploaded — use OnUploadFieldRequest event }  

iiwarning Unfortunately the web server itself can NOT receive files by HTTP protocol. For this purpose you should use some intermediate CGI program, in example, written in C, Perl or PHP (or even in Delphi, if you're running Windows server). If you would like to get examples on how to create scripts which can receive files by HTTP protocol, please check out (PHP manuals), or (CGI Resource Index).  
Check out also OnUploadFieldRequest topic for more detailed description on how to upload data.  

See also
UploadByFieldNames method;  
OnUploadFieldRequest and OnUploadProgress events;  
Read, Abort methods and TransferBufferSize property.