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

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

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:  
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.  

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

See also
Upload method and OnUploadProgress event.