循环调用uploadFile,获取到的uploadTask只有最后一个能够获取到上传进度
uploadImage: function(e) {
console.log("uploadImage");
const tempFilePaths = this.imageList;
for (var i in tempFilePaths) {
const tempFile = tempFilePaths[i];
if (tempFile) {
this.progress = this.progress || [];
this.progress[i] = this.progress[i] || {percent:0, active :true};
this.progress[i].uploadTask = uni.uploadFile({
url: url, //仅为示例,非真实的接口地址
// files: tempFilePaths, // 需要上传的文件列表。使用 files 时,filePath 和 name 不生效//仅5+APP支持
filePath: tempFile,
name: 'upload',
formData: {
'uploadUser': 'test',
'uploadFileName': tempFile,
},
success: (uploadFileRes) => {
console.log(uploadFileRes.data);
},
fail: (uploadFileRes) => {
console.log(uploadFileRes);
},
complete: (uploadFileRes) => {
}
});
const _this = this;
this.progress[i].uploadTask.onProgressUpdate((res) => {
console.log('上传进度' + res.progress);
console.log('已经上传的数据长度' + res.totalBytesSent);
console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
_this.progress[i].percent = res.progress;
// 测试条件,取消上传任务。
// if (res.progress > 50) {
// uploadTask.abort();
// }
});
}
}
},
Dorisup
已解决,自己处理逻辑有问题
2021-11-24 14:46