我正在尝试将照片从我的Vue前端上传到服务器。
const fd = new FormData();
fd.append('image', this.selectedFile)
console.log(fd);
axios.post(`/api/users/46/set-avatar`, fd)
.then(resp => {
console.log(resp);
})
.catch(e => console.log(e));
this.selectedFile = event.target.files[0];
是上载图像的值(通过输入type =“ file”)。
发送此请求时出现400错误。
我不太确定是什么问题,我尝试发送this.selectedFile,但是还是无法正常工作。
我们在项目中使用了招摇,它说:
curl -X POST "http://localhost:8080/api/users/45/set-avatar" -H "accept: */*" -H "Content-Type: multipart/form-data" -F "file=@nyc.jpg;type=image/jpeg"
Request URL
http://localhost:8080/api/users/45/set-avatar