我可以请求从Postman上传文件,但是当我从Angular请求时,会返回WARN“必需的MultipartFile参数'文件'不存在”
它遵循我在API中的资源 .
@PostMapping
public ResponseEntity<Conteudo> publicaConteudo(@RequestParam("file") MultipartFile file) throws JsonParseException, JsonMappingException, IOException {
/* ANYTHING */
return ResponseEntity.ok(new Conteudo());
}
我在Angular的服务 . 我正在使用JWT,但我也尝试使用HttpClient来执行请求 .
upload(file: File, conteudo: Conteudo): Promise<any> {
let formData: FormData = new FormData();
formData.append('file', file, file.name);
/* USING JWT
return this.http.post(this.conteudoUrl, formData)
.toPromise()
.then(response => response.json());
*/
let h1 = new HttpHeaders().set('Authorization', 'Bearer ' + localStorage.getItem('token'));
const req = new HttpRequest('POST',this.conteudoUrl, formData, {
headers: h1
});
return this.httpClient.request(req).toPromise();
}
我怎么能在Postman做
我尝试了很多解决方案,我创建了一个Bean MultipartResolver和其他解决方案,但任何解决我的问题以及我认为更有趣的是它在Postman中工作得很好 .
1 回答
在你的AbstractAnnotationConfigDispatcherServletInitializer类中你有这个方法吗?:
也许你还没有注册多部分过滤器 . 希望这有帮助 .