简体   繁体   English

此请求部分“文件”不存在

[英]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.

相关问题 Tomcat:所需的请求部分“文件”不存在 - Tomcat : Required request part 'file' is not present 出现“不存在所需的请求部分&#39;文件&#39;”错误 - Getting “Required request part 'file' is not present” error Spring 文件上传 - “所需的请求部分不存在” - Spring File Upload - 'Required request part is not present' Spring Boot Required 请求部分“文件”不存在 - Spring Boot Required request part 'file' is not present Spring Thymeleaf所需的请求部分“文件”不存在 - Spring Thymeleaf Required request part 'file' is not present MissingServletRequestPartException:所需的请求部分“文件”不存在 Springboot - MissingServletRequestPartException: Required request part 'file' is not present Springboot 上传文件springboot所需的请求部分“文件”不存在 - upload file springboot Required request part 'file' is not present 所需的要求部分“照片”不存在 - Required request part 'photo' is not present AngularJS JSON Spring MVC 应用程序中的文件上传 400 Bad Request Required 请求部分不存在 - File Upload in AngularJS JSON Spring MVC application 400 Bad Request Required request part is not present 上传图片文件时如何解决“所需的请求部分&#39;文件&#39;不存在”错误 - How to fix “Required request part 'file' is not present” error when uploading image file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM