javascript - 如何将照片上传到服务器
问题描述
我正在尝试将照片从我的 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];
上传图像的值在哪里(通过 input type="file")。发送此请求我收到 400 错误。我不太确定问题出在哪里,我已经尝试发送 this.selectedFile,但它仍然无法正常工作。
我们在项目中使用 swagger,它说:
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
解决方案
推荐阅读
- mediawiki - 列出所有具有自定义标题而不是规范标题的子页面
- android - BroadcastReciever 不工作或 AlarmManager 未设置
- c++ - std::max 在统一初始化和 constexpr int 下表现出意外
- kotlin - kotlin var 的工作方式就像它是不可变的
- laravel - 变形到许多 Laravel 关系
- bash - 没有左值的回显中的重定向运算符?
- html - 网格单元内弹性项目之间的图像导致水平溢出
- reactjs - 在 React 中使用 Knex 查询现有的 Sqlite3 数据库
- swiftui - 如何在swiftui中使用按钮而不是navigationview从视图导航到另一个视图
- c# - 不能多次使用“等待”