首页 > 解决方案 > 拦截器导致“当前请求不是多部分请求”500 错误

问题描述

我正在尝试将图像上传到服务器,但出现了该错误。

我搜索了所有发布的关于堆栈溢出的问题/答案,但没有一个解决我的问题

更新 问题的根源在于http interceptorjwt 在我评论它时它起作用了。

有没有办法解决它?

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 {
    ...
}

标签: angularspring-bootangular6angular8

解决方案


推荐阅读