I am writing a small project with a bunch of Angular 5 at the front and Spring Boot Rest on the backend. It took a form to send files to the server. Here is the function:

sbmt(Images: File[]) { this.http.post('http://localhost:3000/api/product/test', new FormData().append('test', Image[0], Image[0].name)).subscribe(res => { console.log(res); }); } 

Here is the handler on the server:

 @PostMapping("/test") public void test(@RequestParam("test") MultipartFile test) { System.out.println(test.getOriginalFilename()); } 

When I try to download, I get error 500 on the client, and an exception is thrown on the server:

 rg.springframework.web.multipart.MultipartException: Current request is not a multipart request at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:196) ~[spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:112) ~[spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124) ~[spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) ~[spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:131) ~[spring-web-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870) ~[spring-webmvc-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776) ~[spring-webmvc-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.0.4.RELEASE.jar:5.0.4.RELEASE] at 

But how can I still send the file to the server? Rummaged through the entire Internet, including the bourgeois. (In general, there is a large reactive form, but at least I can deal with this, I will do it by analogy) Help, please

    1 answer 1

      sbmt(Form:FormGroup, Images:File[]){ let r = new FormData(); r.append('test', Images[0], Images[0].name); this.http.post('http://localhost:3000/api/product/test', r).subscribe(res=>{ console.log(res); }); } 

    So it worked