上传多张图片时,如何做到监听每一张图片的上传进度。 运行代码时 upload.onProgressUpdate 这个方法在循环中只能调用一遍。求解!!
js代码:
chooseImage:function(){
var that=this
wx.chooseImage({
count: 5,
sizeType: [‘original’,‘compressed’],
sourceType: [‘album’],
success: function(res) {
console.log(res)
console.log(res.tempFilePaths.length)
for (var i = 0; i < res.tempFilePaths.length;i++){
var up = wx.uploadFile({
url: ‘’,
filePath: res.tempFilePaths[i],
name: ‘file’,
success: function (res) {
console.log(res)
console.log(‘上传完毕啦’)
}
})
up.onProgressUpdate((res) => {
console.log(
‘监听进度’
)
that.setData({
percent: res.progress
})
console.log(‘上传进度’, res.progress)
console.log(‘已经上传的数据长度’, res.totalBytesSent)
console.log(‘预期需要上传的数据总长度’, res.totalBytesExpectedToSend)
})
}
},
fail: function(res) {},
complete: function(res) {},
})
},