0

I want to upload file with additional info. I have controller:

@PostMapping(value = "file", consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE,MediaType.MULTIPART_FORM_DATA_VALUE})
public void uploadRecipe(@RequestPart MultipartFile multipartFile, @RequestPart UploadFileRequest uploadFileRequest ) {
 ...
}

POJO

public class UploadFileRequest {
    private String title;
    private String text;

    //getters and setters
}

And i am sending request via postman:

enter image description here

however all i get is:

Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'uploadFileRequest ' is not present]

Why isnt the uploadFileRequest mapped? It is valid json.

Thanks for help!

Johnyb
  • 980
  • 1
  • 12
  • 27

1 Answers1

0

First, you can drop the consumes from your RequestMapping, Spring expects that @RequestParts are being sent in the form of multipart/form-data, you don't need to explicitly call this out (Also, you have a value set here that's not valid for this type of input).

Second, in postman, go to your headers and set Content-Type to multipart/form-data, you should be good to go.

lane.maxwell
  • 5,002
  • 1
  • 20
  • 30