![]() |
![]() ![]() ![]() |
WinHTTP component.
|
type
|
TWinHTTPUploadFieldRequest = procedure(Sender: TObject;
|
FileIndex: Word; UploadStream: TStream;
|
var FieldName, FileName: String) of 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:
|
Parameter | Meaning
|
FileIndex | parameter 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.)
|
|
UploadStream | parameter 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).
|
|
FieldName | should be specified in this event handler. This is the name of form field.
|
|
FileName | is 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);
|
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;
|
Upload method and OnUploadProgress event.
|