DownloadTask.onProgressUpdate

解释:监听下载进度变化

方法参数

Function callback

返回参数说明

示例

在开发者工具中预览效果

扫码体验

请使用百度APP扫码

图片示例

代码示例

-

  1. Page({ data: { alreadyData: 0, targetData: 0 }, downloadFile() { const downloadTask = swan.downloadFile({ url: 'https://smartprogram.baidu.com/docs/img/file-simple.pdf', header: { 'content-type': 'application/json' }, success: res => { console.log(res.tempFilePath); }, fail: err => { console.log('错误码:' + err.errCode); console.log('错误信息:' + err.errMsg); }, complete: () => { } }); downloadTask.onProgressUpdate(res => { console.log('上传进度', res.progress); this.setData({ 'progress': res.progress, 'alreadyData': res.totalBytesWritten, 'targetData': res.totalBytesExpectedToWrite }) console.log('已经上传的数据长度', res.totalBytesWritten); console.log('预期需要上传的数据总长度', res.totalBytesExpectedToWrite); }); } });