![]() |
![]() ![]() ![]() |
auHTTP component.
|
type
|
TauHTTPUploadProgressEvent = procedure(Sender: TObject;
|
DataSize, BytesTransferred,
|
ElapsedTime, EstimatedTimeLeft: Integer;
|
PercentsDone: Byte; TransferRate: Single) of object;
|
|
procedure OnUploadProgress: TauHTTPUploadProgressEvent;
|
The OnUploadProgress event occurs every time when auHTTP 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 auHTTP passes to the OnUploadProgress event handler following parameters:
|
Parameter | Meaning
|
DataSize | total size of data which we currently downloading, in bytes (if possible to determinate).
|
BytesRead | size of already received data, in bytes;
|
ElapsedTime | time elapsed from beginning of download (in seconds);
|
EstimatedTimeLeft | estimated time left before finishing of download (Formula:
|
X := FileSize / BytesRead * ElapsedTime - ElapsedTime);
|
PercentsDone | progress in percents (0%..100%);
|
TransferRate | speed of data transfer (in Kb/s).
|
procedure TForm1.auHTTP1UploadProgress(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;
|
void __fastcall TForm1::auHTTP1UploadProgress(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
|
}
|
Upload method;
|
OnUploadFieldRequest and OnUploadCGITimeoutFailed events.
|