2、图片上传请求地址按照自己的修改
async afterReadList(event) {
let lastFileIndex = this.fileList.length – 1;
let remainingCount = lastFileIndex > 9 ? 0 : 10 – lastFileIndex;
try {
let chooseImageRes = await uni.chooseImage({
count: remainingCount,
sizeType: [‘original’, ‘compressed’],
sourceType: [‘album’],
});
let files = chooseImageRes.tempFilePaths;
let fileListLength = this.fileList.length;
let uploadCount = files.length == 1 ? files.length : 11 – fileListLength;
let uploadPromises = [];
for (let i = 0; i < uploadCount; i++) {
let file = files[i];
uploadPromises.push(new Promise((resolve, reject) => {
uni.uploadFile({
url: wx.getStorageSync(‘apiUrl’) + ‘/common/uploadMinio’,
filePath: file,
name: ‘file’,
formData: {
‘user’: ‘test’
},
header: {
‘Authorization’: ‘Bearer ‘ + wx.getStorageSync(‘token’)
},
success: (uploadFileRes) => {
let res = JSON.parse(uploadFileRes.data);
if (res.code == ‘200’) {
this.fileList.unshift({
url: res.url,
uid: res.url
});
resolve();
} else {
let x = this.fileList.length – 1;
this.fileList.splice(x, 1);
reject();
};
},
fail: (error) => {
reject(error);
}
});
}));
}
await Promise.all(uploadPromises);
} catch (error) {
console.error(‘Error while uploading files’, error);
}
},
原文地址:https://blog.csdn.net/weixin_42433653/article/details/134651438
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_732.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!