locked
TotalBytesToReceive is alwasy zero when downloading file using BackgroundDownloader

    Question

  • Hi,

    I'm using the BackgroundDownloader to download file using POST request and want to display the progress.

    But what I'm getting in the Progress.TotalBytesToReceive is always zero.

    But the last progress callback (when the downloading is completed), it has the correct TotalBytesToReceive value.

    Has anyone seen this issue? Is there a specific header that the server need to set?

    This is the code snippet I'm using.

    var downloader = new BackgroundDownloader();
    Progress<DownloadOperation> progressCallback = new Progress<DownloadOperation>(DownloadProgress);
    var download = await downloader.CreateDownloadAsync(downloadMessage.RequestUri, resultFile, fileContentStream.AsInputStream());
    await download.StartAsync().AsTask(cancelToken, progressCallback);

    private void DownloadProgress(DownloadOperation download)
    {
     Debug.WriteLine("BytesReceived:" + download.Progress.BytesReceived.ToString() + ", totalBytesToReceive:" + download.Progress.TotalBytesToReceive.ToString());
    }

    Thanks!

    Tuesday, March 11, 2014 6:48 PM

Answers

All replies

  • already tried to download another file from another server? it looks the response size header isnt correctly set by the server

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Tuesday, March 11, 2014 7:51 PM
  • I tried it using another server, and I could see the correct totalBytesToReceive.

    So, It looks like the server is not setting the proper header, but I don't know what header needs to be set.

    Do you know what header is used for the totalBytesToReceive?

    Thanks!

    Tuesday, March 11, 2014 8:16 PM
  • Content-Length is used.

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Tuesday, March 11, 2014 9:33 PM