简体   繁体   English

如何恢复大文件下载,并使用ServiceStack客户端获取下载进度?

[英]How do I resume large file downloads, and obtain download progress using the ServiceStack client?

I have a ServiceStack client that calls a service which returns an large data file of between 100MB to 10GB. 我有一个ServiceStack客户端,该客户端调用一个服务,该服务返回100MB至10GB之间的大数据文件。 Currently this client works perfectly over the LAN using the Stream.CopyTo method to save to file. 当前,此客户端使用Stream.CopyTo方法保存到文件,可以在LAN上完美运行。

When the client is being run over a WAN (in addition to over a LAN) the ability to resume a download if it is stopped or loses a connection, as well as see the progress, has become important. 当如果它已停止或失去连接,以及查看进度的客户正在通过WAN运行(除了通过LAN)来继续下载的能力,已成为重要的。

The service supports sending partial files but I am unclear on how to support this in the ServiceStack client or even if it is built in and I do not realise it. 该服务支持发送部分文件,但我对如何支持这个在ServiceStack客户端或者即使它是内置的,我没有意识到这一点还不清楚。

Also the CopyTo method on the stream to copy to another stream does not report its progress so for a large file it can take hours and you can't tell its progress. 另外, CopyTo对法stream复制到另一个stream没有报告其进度等了大文件时,它可能需要几个小时,你不能告诉其进度。 I have seen posts about a CopyFrom method that reports progress but I can't find that anywhere on the classes I am using. 我已经看到有关CopyFrom方法的报告,该方法报告进度,但是在所使用的类的任何地方都找不到。

My environment is the latest version of ServiceStack and latest version of Mono on Mac OS X and .NET 4.5 on Windows. 我的环境是ServiceStack的最新版本以及Mac OS X上的Mono版本和Windows上的.NET 4.5最新版本。

Being able to do concurrent downloads on a file for different segments would be ideal but just been able to resume downloads would be a huge help. 能够对文件进行不同段的并发下载将是理想的选择,但是能够继续下载将是巨大的帮助。

Can someone point out the best way to do this in the ServiceStack client? 可有人指出,在ServiceStack客户做到这一点的最好方法是什么? Most examples I found are just for the normal web client and are very old so wanted to see what the best way is with the later version of dotnet and mono as well as with ServiceStack. 我发现大多数例子只是正常的Web客户端和老迈所以想看看最好的办法是用什么样的dotnet和单声道的更高版本以及与ServiceStack。

If possible a basic example would be perfect. 如果可能的话,一个基本的例子将是完美的。

ServiceStack supports Partial Content Responses for services that return: ServiceStack支持部分内容响应以返回以下服务:

A Physical File 物理文件

return new HttpResult(new FileInfo(filePath), request.MimeType); 

A Memory Stream 内存流

return new HttpResult(ms, "audio/mpeg");

Raw Text 原始文字

return new HttpResult(customText, "text/plain");

Static files served through ServiceStack 通过ServiceStack提供的静态文件

Partial Content is also available in static file downloads served directly through ServiceStack which lets you stream mp3 downloads or should you ever want to your static .html, .css, .js, etc. 直接通过ServiceStack提供的静态文件下载中也提供了部分内容,可让您流mp3下载或在需要时使用静态.html,.css,.js等。

Http Utils Http Utils

See PartialContentResultTests.cs for examples of how to request partial downloads using ServiceStack's built-in HTTP Utils . 有关如何使用ServiceStack的内置HTTP Utils请求部分下载的示例,请参见PartialContentResultTests.cs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM