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

Declaration
type  
  TWinHTTPUploadProgressEvent = procedure(Sender: TObject;  
             DataSize, BytesTransferred,  
             ElapsedTime, EstimatedTimeLeft: Integer;  
             PercentsDone: Byte; TransferRate: Single) of object;  
 
procedure OnUploadProgress: TWinHTTPUploadProgressEvent;  

Description
The OnUploadProgress event occurs every time when WinHTTP uploaded the block of data (size of block equal to TransferBufferSize) to the CGI application. Use it to display the progress of uploading files.  
 
Write OnUploadProgress event handler to show the upload progress (PercentsDone parameter indicate the progress in percents), elapsed and estimated time before finishing download and speed of data transfer.  
 
The WinHTTP passes to the OnUploadProgress event handler following parameters:  
ParameterMeaning  
DataSizetotal size of data which we currently downloading, in bytes (if possible to determinate).  
BytesReadsize of already received data, in bytes;  
ElapsedTimetime elapsed from beginning of download (in seconds);  
EstimatedTimeLeftestimated time left before finishing of download (Formula:  
X := FileSize / BytesRead * ElapsedTime - ElapsedTime);  
PercentsDoneprogress in percents (0%..100%);  
TransferRatespeed of data transfer (in Kb/s).  

Example
Delphi:
procedure TForm1.WinHTTP1UploadProgress(Sender: TObject; DataSize, BytesRead, ElapsedTime, EstimatedTimeLeft: Integer; PercentsDone: Byte; TransferRate: Single; Stream: TStream);  
begin  
  // progress bar position  
  CurrentFileProgressBar.Position := PercentsDone;  
 
  // file size  
  FileSizeLabel.Caption :=   
       Format('File size: %.1f Kb', [FileSize / 1024]);  
 
  // downloaded (in Kb)  
  DownloadedLabel.Caption :=  
      Format('Downloaded: %.1f Kb:', [BytesRead / 1024]);  
 
  // transfer rate  
  TransRateLabel.Caption :=   
       Format('Transfer rate: %.1f Kb/s', [TransferRate]);  
 
  // estimated time left  
  EstTimeLeftLabel.Caption :=   
       Format('Estimated time left: %d:%.2d:%.2d',  
          [EstimatedTimeLeft div 60 div 60,   // hours  
           EstimatedTimeLeft div 60 mod 60,   // minutes  
           EstimatedTimeLeft mod 60 mod 60]); // seconds  
end;  



C++ Builder:

void __fastcall TForm1::WinHTTP1UploadProgress(TObject *Sender,  
      AnsiString ContentType, int FileSize, int BytesRead,  
      int ElapsedTime, int EstimatedTimeLeft,  
      BYTE PercentsDone, float TransferRate, TStream *Stream)  
{  
  // progress bar position  
  ProgressCurrentFile->Position = PercentsDone;  
 
  // file size  
  FileSizeLabel->Caption =  
      Format("File size: %.1f Kb:",   
      ARRAYOFCONST(((float)FileSize / 1024)));  
 
  // downloaded (in Kb)  
  DownloadedLabel->Caption =  
      Format("Downloaded: %.1f Kb:",  
      ARRAYOFCONST(((float)BytesRead / 1024)));  
 
  // transfer rate  
  TransRateLabel->Caption =  
      Format("Transfer rate: %.1f Kb/s",  
      ARRAYOFCONST(((float)TransferRate)));  
 
  // estimated time left  
  EstTimeLeftLabel->Caption =  
      Format("Estimated time left: %d:%.2d:%.2d",  
      ARRAYOFCONST((EstimatedTimeLeft / 60 / 60,    // hours  
                    EstimatedTimeLeft / 60 % 60,    // minutes  
                    EstimatedTimeLeft % 60 % 60))); // seconds  
}  

See also
Upload method and OnUploadFieldRequest event.  
File not found.