Search code examples
javaspring-bootmodel-view-controllermultipartform-data

How To accept File and object in springboot controller java


enter image description here

I want to accept Both file and object that will send on swagger to Spring boot controller **I will Receive request in my controller like **

 @PostMapping("/document/upload")
public void uploadFile(@RequestPart("file") MultipartFile file,@RequestBody FileUpload jsondata){...}

It will not work for me ----------415 Content type 'multipart/form-data;boundary=----WebKitFormBoundaryoOpC1bcOXKJ7ETXw;charset=UTF-8' not supported]


Solution

  • You might have to use @RequestPart instead of @RequestBody. For reference - https://blogs.perficient.com/2020/07/27/requestbody-and-multipart-on-spring-boot/