Full size assigned from the start when uploading a file using Indy

I have this delphi code that basically downloads a file (using Delphi 2010 + Indy 10.5.8 r4743 ), everything works fine, except when I load 100 MB (for example), it seems that Indy assigns the full size (t .e. instantly creates a file with 100 MB of dummy content (*)), then upload the file.

At the end, 100 MB is loaded correctly , but since the boot process is running in the background using a hidden EXEecutable, I based my code on using a temporary file size to update the main user interface

with IdHTTP do
begin
     if FileExists(LocalFile) then
        iLength     := FileSize2(LocalFile)
     else
         iLength    := 0;

     DoExit         := False;
     try
        try
           repeat
                 if ExitApp then
                    Exit;

                 if Not FileExists(LocalFile) then
                    AFileStream     := TFileStream.Create(LocalFile, fmCreate)
                 else
                 begin
                      // File already exist, resume download
                      AFileStream   := TFileStream.Create(LocalFile, fmOpenReadWrite);
                      DoExit        := (AFileStream.Size >= iLength);
                      if (Not DoExit) then
                         AFileStream.Seek(Max(0, AFileStream.Size - 4096), soFromBeginning);
                 end;

                 iRangeEnd          := AFileStream.Size + 50000;

                 if (iRangeEnd < iLength) then
                    Request.Range   := IntToStr(AFileStream.Position) + '-' + IntToStr(iRangeEnd)
                 else
                 begin
                      Request.Range := IntToStr(AFileStream.Position) + '-';
                      DoExit        := True;
                 end;

                 PostTime           := Now;
                 Get(TheURL, AFileStream);
                 IsError            := Not (ResponseCode in [200, 206]);
           until DoExit;

           Disconnect;
        except
              IsError               := True;
        end;    // try/except
     finally
            FreeAndNil(AFileStream);
     end;    // try/finally
end;    // with

indy? , OnWork, .

, IPC ( overkill + , , , , )

(*) , , 60-100 ,

+3
1

, TIdHTTP , , HTTP-. . , , , . , Indy. , . .

+5

All Articles