上传照片功能调试接口遇到坑,后台是需要传formData数据,而小程序没有formData对象,网上有些办法可以实现:链接。
查阅资料,测试成功
wx.uploadFile({
url: this.baseUrl + '/api/real/photoUpload',
filePath: res.tempFilePaths[0],
name: 'file',
headers: {
'X-xxxxx-Client': this.user.token,//这是要token
'Content-Type': 'multipart/form-data' //********划重点
},
formData: {//********划重点
'phone': this.user.phone,
'photoType': 3
},
success: (res) => {}
})