http OnUploadFieldRequest event
Return to Introduction  Previous page  Next page
Applies to
WinHTTP component.  

Declaration
type  
  TWinHTTPUploadFieldRequest = procedure(Sender: TObject;  
    FileIndex: Word; UploadStream: TStream;  
    var FieldName, FileName: Stringof object;  
 
procedure OnUploadFieldRequest: TWinHTTPUploadFieldRequest;  

Description
The OnUploadFieldRequest should be used to put the FieldName, FileName (if required), and data to the stream (UploadStream parameter) for further uploading to the CGI application.  
 
The WinHTTP passes to the OnUploadFieldRequest event handler following parameters:  
ParameterMeaning  
FileIndexparameter specifies the index of data-field/file which should be uploaded. (Note: Total number of fields/files which should be uploaded must be specified on call of Upload method. This parameter is the index of file in queue.)  
 
UploadStreamparameter is the empty stream which should be used to write data for uploading. (Use Stream.Write() method to put data to stream, however, since this is TMemoryStream you can use other methods of TMemoryStreams).  
 
FieldNameshould be specified in this event handler. This is the name of form field.  
 
FileNameis the optional parameter used to specify local path and filename of uploaded file. It does not transmitted to CGI if empty. Use it only if your CGI application should know the real filename.  

Example
procedure TForm1.WinHTTP1UploadFieldRequest(Sender: TObject;  
  FileIndex: Word; UploadStream: TStream; var FieldName, FileName: String);  
begin  
  if FileIndex = 0 then // first file  
   begin  
    FieldName := 'img1';  
    FileName := 'c:\1.jpg';  
   end  
  else // second file, if FileIndex = 1  
   begin  
    FieldName := 'img2';     
    FileName := 'c:\2.jpg';  
   end;  
 
  // put file data to stream  
  (UploadStream as TMemoryStream).LoadFromFile(FileName);  
end;  

See also
Upload method and OnUploadProgress event.