const test = uni.downloadFile({
url: 'http://192.168.20.101:8081/gateway/file-server/fileOss/outsidePreview/xzyc19928853767319429121992885376731942913',
success: (ret) => {
console.log(ret)
},
fail: (ret) => {
console.log(ret)
},
})
test.onProgressUpdate((ret) => {
console.log(ret)
}) - 发布:2025-12-01 15:33
- 更新:45 分钟前
- 阅读:33
产品分类: uniapp/H5
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: 正式
HBuilderX版本号: 4.85
浏览器平台: Chrome
浏览器版本: 142
项目创建方式: HBuilderX
示例代码:
操作步骤:
新建 vue 文件,复制代码示例运行
新建 vue 文件,复制代码示例运行
预期结果:
progress 返回正确的下载进度
progress 返回正确的下载进度
实际结果:
progress 返回错误
progress 返回错误
bug描述:
uni.downloadFile 在 h5 端中,下载进度 progress 一直是 Infinity,在微信小程序端一直是 null
文件能正常下载
vue3 项目,微信基础库3.11.2
这个是你接口的问题吧,h5 端 progress 的 值是这样计算的
xhr.onprogress = function (event) {
downloadTask._callbacks.forEach((callback) => {
var totalBytesWritten = event.loaded
var totalBytesExpectedToWrite = event.total
var progress = Math.round(
(totalBytesWritten / totalBytesExpectedToWrite) * 100
)
callback({
progress,
totalBytesWritten,
totalBytesExpectedToWrite,
})
})
}
会得到 Infinity 是因为正整数除了0