上傳照片功能調試接口遇到坑,後臺是需要傳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) => {}
})