angular - 拦截器导致“当前请求不是多部分请求”500 错误
问题描述
我正在尝试将图像上传到服务器,但出现了该错误。
我搜索了所有发布的关于堆栈溢出的问题/答案,但没有一个解决我的问题
更新
问题的根源在于http interceptor
jwt 在我评论它时它起作用了。
有没有办法解决它?
TS
onSelectFile(files: File[]) {
if (files.length > 0) { this.file = files[0]; }
}
add(){
const uploadImageData = new FormData();
uploadImageData.append('file',this.file);
uploadImageData.append('user',JSON.stringify(this.user));
this.service.add(uploadImageData).subscribe(
data => {this.source=data },
error => { console.log("erreur "); }
);
}
html
<div class="form-group col-md-3 col-lg-3 input-group-sm">
<label>Preuve d'achat</label><br>
<input type="file" (change)="onSelectFile($event.target.files)" enctype='multipart/form-data' >
</div>
背部
@PostMapping("/user")
public Object add(
@RequestParam("file")MultipartFile file, @RequestParam("user")String user)
throws JsonParseException, org.codehaus.jackson.map.JsonMappingException, IOException {
...
}
解决方案
推荐阅读
- function - How can I import an external script from vue.js and use the functions contained in the external script?
- typescript - 打字稿,vue,无法运行笑话
- java - java中的泛型和方法
- java - 片段中的 findViewById 无法获取其视图(在空对象引用上)
- python - 正在打印两个列表
- elasticsearch - 如何在 Elasticsearch 中使用无痛脚本获取数组字段的匹配字段值?
- node.js - 将 unix 时间戳插入 postgres 时间戳列 (node-postgres)
- mongodb - 仅在 mongodb 中为动态字段名称项目嵌套对象
- postgresql - 如何将 Apollographql 连接到多个 Postgres 数据库
- javascript - 我的 javascript 代码不适用于工作 php 的结果