Search code examples
windows-8windows-runtimewindows-8.1

How to make DownloadOperation from BackgroundDownloader resumable


I am adding in functionality to download a large file into my application using the BackgroundDownloader/DownloadOperation functionality. I am using a PushStreamContent in a Web Api controller to serve the data that's being requested using a GET operation.

I have added in the Accept-Ranges header to the response that's received from the Web Api controller, however the BackgroundDownloader doesn't seem to be recognising and attempting to resume downloads. If I call DownloadOperation.Pause() then DownloadOperation.Resume() then the download starts again from the start and doesn't attempt to resume.

In fact if I look in the AC\BackgroundTransferApi folder I can see the .down_data get deleted when I perform the pause. Looking in the down_meta file I can see the Accept-Ranges: bytes header is present and I can see it when looking at the request in Fidder.

What do I need to do on the server side to indicate to the BackgroundDownloader that it supports a resumable transfer? The MSDN documentation simply states Note Paused or incomplete download operations can only be resumed if the server accepts range-requests. which I believe I have satisfied.


Solution

  • The DownloadOperation class has a property that tells you if the operations is resumable: DownloadOperation.GetResponseInformation().IsResumable

    The file is not deleted from AC\BackgroundTransferApi, it is moved to AC\Temp.

    The first HTTP response must include ETag and Accept-Ranges headers:

    ETag: "123ABC"
    Accept-Ranges: bytes
    

    When an operations is resumen, the HTTP request will contain:

    Range: bytes=23000000-
    If-Range: "123ABC"
    

    Next HTTP response should contain something like this:

    ETag: "123ABC"
    Accept-Ranges: bytes
    Content-Range: bytes 23000000-499999999/500000000
    Content-Length: 477000000