http Upload method
Return to Introduction  Previous page  Next page
Applies to
acHTTP 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  
  acHTTP1.Upload(2); // upload 2 files  
{ To specify the data which should uploaded — use OnUploadFieldRequest event }  
end;  

Remarks
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.  
 
iiwarning Some versions of Apache HTTP server has a bug which does not allow to upload files to password protected directories. In case if you always receive timeout error when trying to upload file to password protected URL and even modifications of timeout values in PHP.INI won't help, don't despair and try to upload it to normal directory.  

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