Support resume downloads?

Giganews Newsgroups
Subject: Support resume downloads?
Posted by:  Nicholas Fauchelle (ni…@hyper.net.nz)
Date: Wed, 27 Jul 2005

I have been trying to get idHttp to resume downloads if the download got broken or paused (shown below), however it's not working as expected. I upgraded to Indy10 but still not working right. Here is the code I have. It works fine, but when you click pause, then click resume - it looks like the download restarts for a second then stops.

Global var
  MyStream : TMemoryStream;
  bPause : boolean;

Button1Click  (get download)
  bPause := false;
  idHTTP1.HandleRedirects := True;
  MyStream := TMemoryStream.Create;
  try
    application.ProcessMessages;
    idHTTP1.Get('http:\\site.com\myfile.exe', MyStream);
  except
    showmessage('failed');
  end;

Button2Click  (Pause Download)
  bPause := true;

idHttp1.Work
  application.ProcessMessages;

  If bPause = true then
    begin
      idHTTP1.Disconnect;
      Label1.caption := 'Paused';
    end
  else
    ProgressBar1.Position := AWorkCount;
  label2.caption := IntToStr(AWorkCount);

idHttp1.WorkBegin
  ProgressBar1.Max := AWorkCountMax;

Button3Click (Resume Download)
  idHTTP1.HandleRedirects := True;
  IdHTTP1.Request.ContentRangeStart := MyStream.Size;
  idHTTP1.Get('http:\\site.com\myfile.exe', MyStream);

Best Regards
Nick

Replies