lingochamp / FileDownloader

Multitask、MultiThread(MultiConnection)、Breakpoint-resume、High-concurrency、Simple to use、Single/NotSingle-process
Apache License 2.0
11.02k stars 2.2k forks source link

下载回调FileDownloadListener中的progress()方法 文件大小totalBytes一直为-1 #1072

Open DiuChen opened 6 years ago

DiuChen commented 6 years ago

自己测试想下载该项目zip包路径为:https://github.com/lingochamp/FileDownloader/archive/master.zip 结果一直无法获取到文件大小,开始还以为自己理解不对,于是运行了demo把下载路径替换为该路径结果无法显示进度,自己打印日志文件大小也为-1,想不通

rantianhua commented 6 years ago

在日志里你应该能看到这一行:

W/FileDownloader.FileDownloadUtils: don't get instance length fromContent-Range header

即在 trail connection 中没有获取到文件大小,所以 FileDownloader 把它当成 chunk 资源下载,此时 totalBytes 就一直是 -1 。

duzhigang commented 5 years ago

我用1.7.5也碰到了这种情况,totalBytes 一直是-1。然后尝试其他版本发现1.6.9版本是可以的,但是这个版本又无法支持断点续传功能。 @rantianhua

y4233640 commented 5 years ago

感觉是断点续传功能导致的bug,断点续传不应该默认支持,因为断点续传是需要后台支持的,应该提供打开或关闭断点续传的开关,没有断点续传之前的功能是正常的,回调能拿到文件大小。

y4233640 commented 5 years ago

经过多次不同版本尝试,发现1.7.1都是好的,1.7.2就不行了,应该是1.7.1到1.7.2版本升级修改的内容导致此bug,哪里可以看到之前版本修改的内容?

rantianhua commented 5 years ago

你可以再 https://github.com/lingochamp/FileDownloader/releases 这里看到每个版本的 changelog 。

lucyboy commented 5 years ago

楼主解决了吗 分享一下 我遇到的问题跟你一样

rantianhua commented 5 years ago

这里跟断点续传无关。之所以你遇到这个问题,是服务端没有严格按照协议返回 Content-Range 字段,所以没有获取到文件大小。1.7.1 到 1.7.2 的修正正是从 Content-Length 读取文件大小改为了从 Content-Range 读取,同时请求是 range 变为 0-0 。

rantianhua commented 5 years ago

还可以尝试配置 filedownloader.properties :

download.trial-connection-head-method=true

试试用 HEAD 方法获取文件大小是否支持。