html写个点击事件
js
headimgSel(){
wx.chooseMessageFile({
count: 1, // 最多可以选择的图片张数,默认9
type: 'image',
success (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
var tempFilePaths = res.tempFiles;
wx.getFileSystemManager().readFile({
filePath: tempFilePaths[0].path,
encoding: 'base64',
success: function (res) {
// console.log('data:image/png;base64,' + res.data);
// 将base64格式的图片上传到服务器
wx.request({
url: 'http://192.168.101.69:8081/mStudent/file/upload/base64', // 服务器地址
method: 'POST',
header: {
'content-type': 'application/json' // 默认值
},
data: {
base64: 'data:image/png;base64,' + res.data // base64格式的图片
},
success: function (res) {
if(res.data.code==0){
wx.showToast({
title: '上传成功',icon:'none'
})
}
}
})
}
})
}
})
},