if (!params.method) {
params.method = "GET";
params.header = {
'content-type': 'application/json',
'id': '2',
'token': wx.getStorageSync('token')
}
} else {
params.header = {
"Content-Type": "application/x-www-form-urlencoded",
'id': '2',
'token': wx.getStorageSync('token')
}
}
wx.chooseImage({
success: (res) => {
const tempFilePaths = res.tempFilePaths
wx.setStorageSync('avatar', res.tempFilePaths[0])
console.log(wx.getStorageSync('avatar'))
wx.uploadFile({
url: config.base_url + params.url,
filePath: tempFilePaths[0],
header: params.header,
name: params.name,
formData: params.data,
success: (res) => {
console.log(res)
params.success(res);
},
fail: (err) => {
console.log(err)
}
})
},
fail: (err) => {
console.log(err)
}
})
一加header就报uploadFile:fail Error: socket hang up的错,但注释掉header又无法传token.哪位大神知道怎么解决吗。。
也可以用formData传吧,就看你后台是怎么获取token的了