如何使来自 BackgroundDownloader 的 DownloadOperation 可恢复 [英] How to make DownloadOperation from BackgroundDownloader resumable
问题描述
我正在添加使用 BackgroundDownloader
/DownloadOperation
功能将大文件下载到我的应用程序中的功能.我在 Web Api 控制器中使用 PushStreamContent
来提供使用 GET 操作请求的数据.
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.
我已将 Accept-Ranges
标头添加到从 Web Api 控制器收到的响应中,但是 BackgroundDownloader
似乎无法识别并尝试恢复下载.如果我调用 DownloadOperation.Pause()
然后 DownloadOperation.Resume()
然后从头开始下载并且不会尝试恢复.
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.
事实上,如果我查看 AC\BackgroundTransferApi
文件夹,我可以看到 .down_data
在我执行暂停时被删除.查看 down_meta
文件,我可以看到 Accept-Ranges: bytes
标头存在,我可以在查看 Fidder 中的请求时看到它.
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.
我需要在服务器端做什么来向 BackgroundDownloader
表明它支持可恢复传输?MSDN 文档很简单状态 注意暂停或不完整的下载操作只能在服务器接受范围请求时恢复.
我相信我已经满足了.
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.
推荐答案
DownloadOperation
类有一个属性可以告诉您操作是否可恢复:DownloadOperation.GetResponseInformation().IsResumable代码>
The DownloadOperation
class has a property that tells you if the operations is resumable: DownloadOperation.GetResponseInformation().IsResumable
文件没有从AC\BackgroundTransferApi
中删除,而是移动到AC\Temp
.
The file is not deleted from AC\BackgroundTransferApi
, it is moved to AC\Temp
.
第一个 HTTP 响应必须包含 ETag
和 Accept-Ranges
标头:
The first HTTP response must include ETag
and Accept-Ranges
headers:
ETag: "123ABC"
Accept-Ranges: bytes
恢复操作时,HTTP 请求将包含:
When an operations is resumen, the HTTP request will contain:
Range: bytes=23000000-
If-Range: "123ABC"
下一个 HTTP 响应应包含如下内容:
Next HTTP response should contain something like this:
ETag: "123ABC"
Accept-Ranges: bytes
Content-Range: bytes 23000000-499999999/500000000
Content-Length: 477000000
这篇关于如何使来自 BackgroundDownloader 的 DownloadOperation 可恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!