[英]This request part 'file' is not present
I saw other similiar post with answers but since it's not helping me i'm posting this.我看到其他类似的帖子有答案,但因为它对我没有帮助,所以我发布了这个。
I'm using Java/Angular 11, i'm making Post Request sending data in FormData but it keeps giving me我正在使用 Java/Angular 11,我正在 Post Request 在 FormData 中发送数据,但它一直给我
Request part 'file' is not present
My Server我的服务器
@PostMapping(value = /add, consumes = MediaType.MULTIPART_FORM_DATA_VALUE,headers = ("content-type=multipart/*"))
public ApiResponseEntity add(@RequestParam("file") MultipartFile file,
@RequestParam("foo") Foo foo) throws IOException {
My Client(Angular)我的客户(角度)
formData = new FormData()
this.formData.append("file", ev.target.files[0]));
this.formData.append("foo",JSON.stringify(FooDTO));
this.httpClient
.post<any>(this.baseURL + apiURL + "/add", entity, this.httpOptions)
.subscribe((response: any) => {
resolve(response);
}, reject);
My Payload: ------WebKitFormBoundarysDMcWqKZNsayiMSX Content-Disposition: form-data;我的有效负载:-----WebKitFormBoundarysDMcWqKZNsayiMSX 内容处置:表单数据; name="file";
名称=“文件”; filename="abc.png" Content-Type: image/png
文件名="abc.png" 内容类型:image/png
------WebKitFormBoundarysDMcWqKZNsayiMSX Content-Disposition: form-data; ------WebKitFormBoundarysDMcWqKZNsayiMSX Content-Disposition: form-data; name="foo"
名称=“富”
{... } ------WebKitFormBoundarysDMcWqKZNsayiMSX-- {... } ------WebKitFormBoundarysDMcWqKZNsayiMSX--
Where did i go wrong?我在哪里 go 错了? Thanks for viewing and answering!
感谢观看和回答!
NOTE: HttpOption has Content-type: multipart/form-data, i also tried to use @RequestPart but the result still the same注意:HttpOption 具有 Content-type: multipart/form-data,我也尝试使用 @RequestPart 但结果仍然相同
I think you are not passing formData in your http post, modify the below line of code from我认为您没有在 http 帖子中传递 formData,请修改以下代码行
this.httpClient
.post<any>(this.baseURL + apiURL + "/add", entity, this.httpOptions)
.subscribe((response: any) => {
resolve(response);
}, reject);
as below如下
this.httpClient.post<any>(this.baseURL + apiURL + "/add", formData, this.httpOptions)
.subscribe((response: any) => {
resolve(response);
}, reject);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.