上传图片时在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);
}
}
});
}
});
},
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。