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

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

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.  

procedure TForm1.UploadBtnClick(Sender: TObject);  
  acHTTP1.Upload(2); // 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.  
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.