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

StackOverflow https://stackoverflow.com/questions/23548562

Вопрос

I have a ServiceStack client that calls a service which returns an large data file of between 100MB to 10GB. Currently this client works perfectly over the LAN using the Stream.CopyTo method to save to file.

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.

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.

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. I have seen posts about a CopyFrom method that reports progress but I can't find that anywhere on the classes I am using.

My environment is the latest version of ServiceStack and latest version of Mono on Mac OS X and .NET 4.5 on Windows.

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? 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.

If possible a basic example would be perfect.

Это было полезно?

Решение

ServiceStack supports Partial Content Responses for services that return:

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

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.

Http Utils

See PartialContentResultTests.cs for examples of how to request partial downloads using ServiceStack's built-in HTTP Utils.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top