Android:在许多部分下载单个文件 [英] Android : Download a single file in many parts
问题描述
我开发了一个类似Internet Download Manager for Android的应用程序。
I developing an application like Internet Download Manager for Android.
我想知道如何在Android中下载文件的不同部分,就像在IDM中一样。
I want to know how to download different parts of file in Android as it is done in IDM.
如何在下载之前获取文件的元数据以及如何下载部分文件?
How can I get the metadata of file before download and how to download files in parts?
没有用户名密码或任何下载限制...只需通过网址简单下载。
There is no username-password or any restrictions in downloading... just simple download by url.
推荐答案
假设您正在使用HTTP下载,您将要使用 HEAD
http动词和 RANGE
http标头。
Assuming you're using HTTP for the download, you'll want to use the HEAD
http verb and RANGE
http header.
HEAD
将为您提供文件大小(如果可用),然后 RANGE
允许你下载一个字节范围。
HEAD
will give you the filesize (if available), and then RANGE
lets you download a byte range.
一旦你有了文件大小,将它分成大致相等大小的块并为每个块生成下载线程。完成所有操作后,按正确的顺序编写文件块。
Once you have the filesize, divide it into roughly equal sized chunks and spawn download thread for each chunk. Once all are done, write the file chunks in the correct order.
编辑:
如果你不这样做知道如何使用 RANGE
标题,这是另一个SO答案,解释如何: https://stackoverflow.com/a/6323043/1355166
If you don't know how to use the RANGE
header, here's another SO answer that explains how: https://stackoverflow.com/a/6323043/1355166
这篇关于Android:在许多部分下载单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!