locked
metro应用实现断点续传的问题 RRS feed

  • Question

  • 大家好!
    咨询一个问题。
    问题前景用中需要实现断点续传下载服务器上面的音乐,服务器支持断点续传。
    实现下载的时候想用DownloadOperation来实现,有2个疑问,不利于我实现断点续传
    第一:DownloadOperation的Resume()方法,是重新下载而不是恢复从暂停的地方开始下载。
    第二:他下载的数据并不是时候保存到本地文件的。感觉是在下载完后一次性保存的。
    有明白的同学指点下断点续传怎么实现。
    还有一个问题。开始实现的时候我有使用过HttpClient来实现下载。
    发现HttpClient的Timeout需要设置2分钟才能下载下来。不然老失败。2分钟等待时间太长。让人很烦恼。是不是与网速有关系。现在的pad基本都是使用无线。网速应该不是很快。


    • Edited by caiyunol Wednesday, August 22, 2012 2:41 AM
    Wednesday, August 22, 2012 2:35 AM

Answers

  • Hello everyone!
    Advisory question.
    Issues prospects need to implement a resumable download music above the server, the server supports resumable.
    Achieve download time using DownloadOperation to achieve, there are 2 questions, to the detriment of my implementation resumable
    First: Resume of the DownloadOperation () method, is re-download not restore from suspend place to start the download.
    Second: when he downloaded data is not saved to a local file. Feeling is that after downloading a one-time saving.
    Understand why students pointing resumable implementations.
    There is also a problem. Started when I have used HttpClient to download.
    Discover HttpClient Timeout needs to be set to 2 minutes to download. Otherwise the old failed. 2 minute wait time is too long. Makes people great trouble. Is associated with speed. Pad is used for basic wireless now. Speeds should not fast.


    According to the bing translator :) , here are the answers:

    1) Resume method does resume on cases where resume is possible. Meaning if the server accepts range-requests, the download would resume, otherwise restart.

    2) When you are creating the storage file store your data, you have to use GenerateUnique name enum value to avoid overriding the existing file.

    StorageFile destinationFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
                        destination, CreationCollisionOption.GenerateUniqueName);
    
    BackgroundDownloader downloader = new BackgroundDownloader();
    DownloadOperation download = downloader.CreateDownload(source, destinationFile)

    3) If the HttpClient is giving you a hard time with the download, you can always embellish it with a download progress. This would sustain the fluid UI and avoid non responsive application. Here is an example that is to be used with servers which allow chunked encoding: Download / Send Request Async with Progress

    Hope it helps, and you might want to try to post it to a local group rather than the english one. You might get more responses.


    Can Bilgin
    Blog CompuSight


    Wednesday, August 22, 2012 10:33 AM