-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
下载文件时progress的totalBytes总是-1 #1050
Comments
你应该是使用 OkHttp 这个网络库,该网络库是支持 SPDY 协议的,所以你日志里面的 request header 和 response header 都是小写。不过 OkHttp 里面获取 header 的方式是不关心大小写的:
我自己测试也确实是正常的。所以需要确认一下你是如何引入 OkHttp 的?是自定义的 |
|
经过多次试验,发现totalBytes并不总是-1,下面是同一个下载地址的log。 totalBytes为正常的log: V/FileDownloader.DownloadTaskHunter: call start Url[https://devimg.xiezixiansheng.com/users/3/322/handzip/t100_145376.zip], Path[/storage/emulated/0/download/t100_145376.zip] Listener[com.handwriting.makefont.commlogic.FileDownloadManager$1@6570bd5], Tag[null] totalBytes为-1的log: V/FileDownloader.DownloadTaskHunter: call start Url[https://devimg.xiezixiansheng.com/users/3/322/handzip/t100_145376.zip], Path[/storage/emulated/0/download/t100_145376.zip] Listener[com.handwriting.makefont.commlogic.FileDownloadManager$1@6865e35], Tag[null] |
使用默认下载设置复现了这个问题,这次没有同时下载多个,直接下载的https://devimg.xiezixiansheng.com/users/3/322/handzip/t100_145376.zip。(还是上面那个下载地址) log如下: V/FileDownloader.DownloadTaskHunter: call start Url[https://devimg.xiezixiansheng.com/users/3/322/handzip/t100_145376.zip], Path[/storage/emulated/0/download/t100_145376.zip] Listener[com.handwriting.makefont.commlogic.FileDownloadManager$1@30146e1], Tag[null] 再补充个正常log: |
问题知道了,从你最后给的异常的日志可以看到,第一次请求的时候,request header 为:
对应的 response header 为:
但是同样的请求,在你提供的正常的日志里面, response header 为:
第一次的请求就是为了获取文件长度,并不下载实际内容,所以 GET 请求里面,Range 为 0-0 ,这是一个正常的请求,而服务器却返回了 416 ,这种情况下,会直接重试第一次请求且去掉了 Range ,然而此时服务器又没有在 response 里面返回 Content-Range 字段,导致没有获取到文件长度。总的来说,这是服务器没有严格按照协议实现的结果,并不是 FileDownloader 的问题。 当然,你也可以尝试通过 FileDownloader 绕过这个问题。有两种方式:
你可以尝试上面两种方式,且希望你能提供这两种方式的反馈。 |
反馈两种方式的多次测试结果: 2.使用1.7.5-SNAPSHOT,结果成功,附上log。 |
OK,那等 1.7.5 release 吧 |
下载文件地址是:https://devimg.xiezixiansheng.com/users/3/322/handzip/t100_145366.zip
下载在主进程里。版本是1.7.4。看log里请求是有返回文件大小的,不知道为什么回调时totalBytes变成-1,麻烦看看有没有解决方法,谢谢。
补充:使用火狐浏览器,或HttpURLConnection 是可以正确拿到这个文件大小的。
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
long size = connection.getContentLength();
以下是FileDownloader的log:
V/FileDownloader.DownloadTaskHunter: call start Url[https://devimg.xiezixiansheng.com/users/3/322/handzip/t100_145366.zip], Path[/storage/emulated/0/download/t100_145366.zip] Listener[com.handwriting.makefont.commlogic.FileDownloadManager$1@594bd57], Tag[null]
V/FileDownloader.DownloadTaskHunter: the task[948619801] has been into the launch pool.
V/FileDownloader.FileDownloadEventPool: setListener event.service.connect.changed
D/FileDownloader.FileDownloadMessenger: notify begin 948619801@com.liulishuo.filedownloader.DownloadTask@6d2152d
V/FileDownloader.DownloadTaskHunter: filedownloader:lifecycle:start com.liulishuo.filedownloader.DownloadTaskHunter@7b4ea62 by 11
V/FileDownloader.FileDownloadList: add list in all 948619801@com.liulishuo.filedownloader.DownloadTask@6d2152d 11 1
D/FileDownloader.FileDownloadManager: request start the task with url(https://devimg.xiezixiansheng.com/users/3/322/handzip/t100_145366.zip) path(/storage/emulated/0/download/t100_145366.zip) isDirectory(FALSE)
D/FileDownloader.FileDownloadUtils: can't continue 948619801 file not suit, exists[FALSE], directory[FALSE]
D/FileDownloader.DownloadMgrInitialParams: initial FileDownloader manager with the customize connection creator: cn.dreamtobe.filedownloader.OkHttp3Connection$Creator@7e7d729
D/FileDownloader.MessageSnapshotGate: ~~~callback 948619801 old[11] new[1] 1
D/FileDownloader.FileDownloadMessenger: notify pending 948619801@com.liulishuo.filedownloader.DownloadTask@6d2152d
D/FileDownloader.MessageSnapshotGate: updateKeepFlow
D/FileDownloader.ConnectTask: <---- 948619801 request header {range=[bytes=0-0], user-agent=[FileDownloader/1.7.4]}
D/FileDownloader.MessageSnapshotGate: ~~~callback 948619801 old[1] new[6] 1
D/FileDownloader.FileDownloadMessenger: notify started 948619801@com.liulishuo.filedownloader.DownloadTask@6d2152d
D/FileDownloader.MessageSnapshotGate: updateKeepFlow
D/FileDownloader.ConnectTask: ----> 948619801 response header {accept-ranges=[bytes], access-control-allow-methods=[POST,GET,HEDA], access-control-allow-origin=[], access-control-max-age=[0], cache-control=[no-cache], connection=[keep-alive], content-length=[0], content-md5=[a3wcSB5xp3pUrwzvHno14w==], content-range=[bytes /2312060], content-type=[application/zip], date=[Thu, 07 Jun 2018 06:29:48 GMT], eagleid=[3c1ce20515283529885596204e], etag=["6B7C1C481E71A77A54AF0CEF1E7A35E3"], last-modified=[Tue, 13 Mar 2018 07:06:19 GMT], server=[Tengine], timing-allow-origin=[], via=[cache8.l2nu17-1[61,416-0,M], cache36.l2nu17-1[62,0], kunlun6.cn36[66,416-1280,M], kunlun5.cn36[68,0]], x-cache=[MISS TCP_MISS dirn:-2:-2 mlen:-1], x-oss-hash-crc64ecma=[17755995990363745947], x-oss-object-type=[Normal], x-oss-request-id=[5B18D0DC6B3F22911F7845D4], x-oss-server-time=[61], x-oss-storage-class=[Standard], x-swift-cachetime=[0], x-swift-error=[orig response 4XX error], x-swift-savetime=[Thu, 07 Jun 2018 06:29:48 GMT]}
D/FileDownloader.FileDownloadUtils: etag find "6B7C1C481E71A77A54AF0CEF1E7A35E3" for task(948619801)
D/FileDownloader.ConnectTask: <---- 948619801 request header {if-match=["6B7C1C481E71A77A54AF0CEF1E7A35E3"], user-agent=[FileDownloader/1.7.4]}
D/FileDownloader.ConnectTask: ----> 948619801 response header {accept-ranges=[bytes], access-control-allow-methods=[POST,GET,HEDA], access-control-allow-origin=[], access-control-max-age=[0], connection=[keep-alive], content-length=[2312060], content-md5=[a3wcSB5xp3pUrwzvHno14w==], content-type=[application/zip], date=[Thu, 07 Jun 2018 06:29:48 GMT], eagleid=[3c1ce20515283529886486607e], etag=["6B7C1C481E71A77A54AF0CEF1E7A35E3"], last-modified=[Tue, 13 Mar 2018 07:06:19 GMT], server=[Tengine], timing-allow-origin=[], via=[cache8.l2nu17-1[11,200-0,M], cache36.l2nu17-1[12,0], kunlun6.cn36[15,200-0,M], kunlun5.cn36[17,0]], x-cache=[MISS TCP_MISS dirn:-2:-2 mlen:-1], x-oss-hash-crc64ecma=[17755995990363745947], x-oss-object-type=[Normal], x-oss-request-id=[5B18D0DCA56E418A1E6B9DBB], x-oss-server-time=[5], x-oss-storage-class=[Standard], x-swift-cachetime=[3600], x-swift-savetime=[Thu, 07 Jun 2018 06:29:48 GMT]}
D/FileDownloader.FileDownloadUtils: etag find "6B7C1C481E71A77A54AF0CEF1E7A35E3" for task(948619801)
W/FileDownloader.FileDownloadUtils: don't get instance length fromContent-Range header
D/FileDownloader.MessageSnapshotGate: ~~~callback 948619801 old[6] new[2] 1
D/FileDownloader.FileDownloadMessenger: notify connected 948619801@com.liulishuo.filedownloader.DownloadTask@6d2152d
D/FileDownloader.MessageSnapshotGate: updateKeepFlow
D/FileDownloader.ConnectTask: <---- 948619801 request header {if-match=["6B7C1C481E71A77A54AF0CEF1E7A35E3"], range=[bytes=0-], user-agent=[FileDownloader/1.7.4]}
D/FileDownloader.ConnectTask: ----> 948619801 response header {accept-ranges=[bytes], access-control-allow-methods=[POST,GET,HEDA], access-control-allow-origin=[], access-control-max-age=[0], age=[1], connection=[keep-alive], content-length=[2312060], content-md5=[a3wcSB5xp3pUrwzvHno14w==], content-range=[bytes 0-2312059/2312060], content-type=[application/zip], date=[Thu, 07 Jun 2018 06:29:48 GMT], eagleid=[3c1ce20715283529893235346e], etag=["6B7C1C481E71A77A54AF0CEF1E7A35E3"], last-modified=[Tue, 13 Mar 2018 07:06:19 GMT], server=[Tengine], timing-allow-origin=[*], via=[cache8.l2nu17-1[11,200-0,M], cache36.l2nu17-1[12,0], kunlun6.cn36[0,206-0,H], kunlun7.cn36[0,0]], x-cache=[HIT TCP_MEM_HIT dirn:-2:-2 mlen:-1], x-oss-hash-crc64ecma=[17755995990363745947], x-oss-object-type=[Normal], x-oss-request-id=[5B18D0DCA56E418A1E6B9DBB], x-oss-server-time=[5], x-oss-storage-class=[Standard], x-swift-cachetime=[3600], x-swift-savetime=[Thu, 07 Jun 2018 06:29:48 GMT]}
D/FileDownloader.DownloadRunnable: the connection[-1] for 948619801, is connected range[0, -1) current offset[0] with code[206]
D/FileDownloader.FetchDataTask: start fetch(-1): range [0, -1), seek to[0]
I/FileDownloader.DownloadStatusCallback: inspectNeedCallbackToUser need callback to user
I/FileDownloader.DownloadStatusCallback: handleProgress update model's status with progress
I/FileDownloader.DownloadStatusCallback: handleProgress notify user progress status
D/FileDownloader.MessageSnapshotGate: ~~~callback 948619801 old[2] new[3] 1
D/FileDownloader.FileDownloadMessenger: notify progress 948619801@com.liulishuo.filedownloader.DownloadTask@6d2152d 4096 -1
The text was updated successfully, but these errors were encountered: