Mathiyazhagan
Mathiyazhagan

Reputation: 1429

HttpWebRequest Download always starts from begining of file not resuming

I'm trying to add the pause/resume functionality of my download utility, and it seems that the HttpWebRequest.Addrange() method doesn't work correctly. I tried to use it to resume a download but the webresponse always starts from the beginning of the file, each time i run my app.

Below is my code:

  var request = (HttpWebRequest)HttpWebRequest.Create(url);
  request.AddRange((int)iExistLen);
  var downloadStream = request.GetResponse().GetResponseStream();
     for (int byteSize = 0; (byteSize = fileProvider.Read()) > 0;)
            {
                downloadStream.Read(buffer, 0, buffer.Length);
            };

Below is my Download URL: https://mathinew.blob.core.windows.net/sharedfolder/testfile006.txt

Please let me know if anybody faced the similar issue, or anything I'm doing wrong here

Upvotes: 0

Views: 190

Answers (1)

argaz
argaz

Reputation: 1488

From the URL I can see that you're using Azure Blob Storage.

By default it doesn't respect Range header and you need to set the version to 2011-08-18 or newer to make it work, using the x-ms-version header, for example:

request.Headers["x-ms-version"] = "2011-08-18";

You can also set the version globally for Range headers to be working by default, check out this question and this MSDN page for more info.

Upvotes: 1

Related Questions