1.wxml触发选择图片事件
<button type="primary" bindtap="_choseImage">选择头像</button>
2.选择图片
_choseImage() {
let _this = this;
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success(res) {
const tempFilePaths = res.tempFilePaths
_this.setData({
src: tempFilePaths[0]
})
}
})
},
3.执行上传
_submit() {
let src = this.data.src;
let extName = src.split(".").pop();
let cloudPath = "web/" + new Date().getTime() + "." + extName;
wx.cloud.uploadFile({
cloudPath,
filePath: src,
}).then(res=>{
}).catch(err=>{})
},