upFileImg (file){
return new Promise((resolve, reject) => {
let token =uni.getStorageSync(keys.token);
uni.uploadFile({
url: ‘oss上传图片地址’,
name: 'file',
file: file,
filePath:file,
header: {
"Authorization": token,
},
formData: {
'imageSource': '看后端需要什么'
},
success: (uploadFileRes) => {
resolve(JSON.parse(uploadFileRes.data));
},
fail:(data) =>{
reject(data)
}
});
});
},
调用
async onChooseAvatar(e) {
const { avatarUrl } = e.detail;
const result = await upFileImg(avatarUrl);
const avatarUrlNew = result.data;
},