diff --git a/imageknife/src/main/ets/components/imageknife/networkmanage/DownloadClient.ets b/imageknife/src/main/ets/components/imageknife/networkmanage/DownloadClient.ets index 51f099e..bdc85e0 100644 --- a/imageknife/src/main/ets/components/imageknife/networkmanage/DownloadClient.ets +++ b/imageknife/src/main/ets/components/imageknife/networkmanage/DownloadClient.ets @@ -46,9 +46,12 @@ export class DownloadClient implements IDataFetch { loadTask = downloadTask; loadTask.on('progress', (receivedSize, totalSize) => { - let percent = Math.round(((receivedSize * 1.0) / (totalSize * 1.0)) * 100) - if (request.progressFunc) { - request.progressFunc(percent); + if(totalSize > 0) { + // 并不是所有服务器都会返回totalSize 当没有文件大小的时候,下载进度没有百分比回调,只能知道目前下载了多少数据量 + let percent = Math.round(((receivedSize * 1.0) / (totalSize * 1.0)) * 100) + if (request.progressFunc) { + request.progressFunc(percent); + } } });