上传图片时在formData中携带token信息
注意:在formData中携带参数时,不要配置header头信息,否则会造成后台接收不到前台传递的信息
// 上传头像
chooseImg() {
let that = this;
let token = that.$tool.getCache('token')
console.log('token',that.$tool.getCache('token'))
uni.chooseImage({
count: 1, //默认9
// sizeType: ['original'], //, original 原图,compressed 压缩图,默认二者都有
sourceType: ['album'], //从相册选择 'album' camera
success: function(res) {
let tempFilePaths = res.tempFilePaths;
uni.uploadFile({
fileType: "image",
url: that.$http.baseUrl + 'api/upload/image',
filePath: tempFilePaths[0],
name: 'iFile',
formData:{
iFile:tempFilePaths[0],
token:token,
},
success: (res) => {
console.log(res,"上传图片");
if(res.statusCode == 200){
if (JSON.parse(res.data).code == 500) {
that.$tool.toast('请上传小于2M的图片')
return
}
let avatar = JSON.parse(res.data).data;
}else{
that.$tool.toast(res.message);
}
}
});
}
});
},