uploadImage: function () {
var that = this
wx.chooseImage({
success: function (res) {
var tempFilePaths = res.tempFilePaths
wx.showToast({
title: ‘识别中,请稍候’,
icon: ‘loading’,
duration: 2000
})
console.log(tempFilePaths[0])
wx.uploadFile({
url: ‘https://www.hanqi86.wang/uploads/WX/’,
header: {
‘content-type’: ‘multipart/form-data’
},
filePath: tempFilePaths[0],
name: ‘file’,
formData: {
‘user’: ‘test’
},
success: function (res) {
console.log(“上传成功”);
console.log(res.data)
wx.hideToast()
var data = JSON.parse(res.data)
if (!data.attributes) {
that.setData({
userInfo: {
avatarUrl: data.url,
tips: ‘未识别到颗粒’
}
})
return
}
const genders = {
‘Male’: ‘帅哥’,
‘Female’: ‘美女’
}
that.setData({
userInfo: {
avatarUrl: data.url,
tips: ‘一位’ + data.attributes.age.value + ‘岁的’ + genders[data.attributes.gender.value]
}
})
//do something
},
fail: function (res) {
console.log(“上传失败” + res.data);
wx.showToast({
title: ‘上传失败’,
icon: ‘loading’,
duration: 2000
})
}
})
console.log(“完成”);
wx.showToast({
title: ‘识别完成’,
icon: ‘loading’,
duration: 2000
})
}
})
}