在 Silverlight 4 OOB 中恢复文件下载

发布于 2024-10-22 03:12:01 字数 445 浏览 2 评论 0原文

我有一个 Silverlight 4 浏览器外应用程序,如果下载因任何原因中断,该应用程序需要能够恢复外部文件的下载。我希望能够恢复而不是从头开始重新启动,因为文件会相当大,并且我们有可能让用户使用较慢的连接。

我在

http 找到了一些代码://www.codeproject.com/Tips/157532/Silverlight-4-OOB-HTTP-Download-Component-with-Pau.aspx

但其中似乎有很多错误,所以我不完全是相信我能够让它发挥作用。

因此,如果有人有任何其他原创建议或替代方案,我想听听。

谢谢,

I have a Silverlight 4 out-of-browser application that needs to be able to resume the download of an external file if the download is interrupted for any reason. I would like to be able resume instead of restart from the beginning because the file will be rather large and we have the potential to have users on slower connections.

I found some code at,

http://www.codeproject.com/Tips/157532/Silverlight-4-OOB-HTTP-Download-Component-with-Pau.aspx

but there seems to be numerous errors in it, so I'm not exactly confident that I'll be able to get it to work.

So, if anyone has any other original suggestions or alternatives, I'd like to hear them.

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰つ倒转 2024-10-29 03:12:01

您可能考虑的一种方法是使用 HTTP/1.1 Acccept-Ranges 响应标头和 Range 请求标头来管理下载。

确保您下载的资源包含标题:-

接受范围:字节

请求时的字节(默认情况下,IIS 发送的静态文件将执行此操作)。

现在,使用 ClientHTTP 堆栈发出初始“HEAD”请求,以确定服务器将接受请求中的 Range: bytes= 标头,并查找要发送的内容的总大小。

然后,您对包含标头的资源发出“GET”请求:-

范围:字节=0-65535

这将下载的内容限制为仅第一个 64K 块。然后,您可以重复相同的请求:-

范围:字节=65536-131071

每次都可以将响应流的内容保存到目标文件中。您可以跟踪收到的字节数。当您确定可能未满的最终块时,只需使用如下标头:-

范围:字节=131072-

这将读取到文件末尾。

如果对服务器的请求失败,您可以在此序列中的适当位置恢复。

您需要优雅地降级,如果服务器在初始“HEAD”请求中不包含 Accept-Ranges 标头,那么您只需下载整个文件。

One approach you might consider is managing the download using the HTTP/1.1 Acccept-Ranges response header and the Range request header.

Make sure the resource you are downloading will include the header:-

Accept-Ranges: bytes

when it is requested (a static file sent by IIS will do this by default).

Now using the ClientHTTP stack you make an initial "HEAD" request to determine the server will accept a Range: bytes= header in the request and find the total size of the content to be sent.

You then make a "GET" request for the resource including the header:-

Range: bytes=0-65535

This limits the downloaded content to just the first 64K chunk. You then repeat the same request with:-

Range: bytes=65536-131071

Each time you can save the content of the response stream to your destination file. You keep track of how many bytes you have received. When you determine the final chunk which is likely to less than full just use a header like:-

Range: bytes=131072-

That will read to the end of file.

If the requests to the server are fail you can resume at an appropriate point in this sequence.

You need to be degrade gracefully, if the server does not include the Accept-Ranges header in the initial "HEAD" request then you'll just have to download the whole file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文