请问下大家伙,uniapp的APP端怎样同时上传两个文件?
1***@139.com
- 发布:2023-09-21 22:10
- 更新:2023-09-21 23:16
- 阅读:125
喜欢技术的前端 - QQ---445849201
可以做个同步循环处理
uni.chooseImage({
success: async (res) => {
const tempFilePaths = res.tempFilePaths;
for(let i = 0;i<tempFilePaths.length;i++){
let res = await _this.uploadImgs(tempFilePaths[i])
}
}
});
uploadImgs(tempFilePaths){
return new Promise((resolve,reject)=>{
uni.uploadFile({
url: '你的上传地址',
filePath: tempFilePaths,
fileType:'image',
name: 'file',
formData: {
mn: 'image'
},
header:{
'Content-Type':'multipart/form-data',
'Authorization':'Bearer '+uni.getStorageSync('token'),
},
success: (res) => {
console.log(res);
resolve('你的图片地址');
},
fail() {
reject('error');
uni.showToast({
title:'上传失败',
icon:'none'
})
}
});
})
}
1***@139.com (作者)
非常感谢老铁。真心感谢
2023-09-21 23:38
喜欢技术的前端
回复 1***@139.com: 客气,解决问题就好☺
2023-09-21 23:57