把用户的头像上传,限制在2M以内
代码
that.onChooseAvatar = (e) => {
console.log('onChooseAvatar2', e);
const avatarUrl = e.target.avatarUrl;
let FileSystemManager = wx.getFileSystemManager()
FileSystemManager.getFileInfo({
"filePath": avatarUrl,
success(res) {
console.log('FileInfo-res', res)
if (res.size > 1024 * 1024 * 2) {
wx.showToast({
title: '所选图片过大,请选择2M以内的图片',
icon: 'none'
})
} else {
let imgPath =
`nhs/userUpload/avatarUrl/${wx.getStorageSync('userToken')}${new Date().getTime() + Math.floor(Math.random() * 150)}`
uploadImage.uploadFile(
avatarUrl, imgPath,
function(result) {
that.saveUserInfo({
'avatarUrl': result
})
},
function(result) {
wx.hideLoading();
}
)
}
},
fail(err) {
console.log('FileInfo-err', err)
},
})
}