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

Declaration
function Upload(NumberOfFields: Word): Boolean; // returns False if busy  

Description
The Upload method starts HTTP request to upload data via HTTP protocol, using multipart/form-data POST method, introduced in RFC 1867.  
 
Before starting the uploading, it requests fields and their names 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.  

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

Remark
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.net (PHP manuals), or www.cgi-resources.com (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.