How to make DownloadOperation from BackgroundDownloader resumable

邮差的信 提交于 2019-12-11 23:46:52

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/27405298/how-to-make-downloadoperation-from-backgrounddownloader-resumable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!