I want to send a file and a json model at one post request.
My Request Mapping looks like that:
@PostMapping(\"{id}/files\")
public MyOutput
You can try to use instead of this
@RequestPart("file") MultipartFile file
use this
@RequestParam(value = "file",required = false) MultipartFile file
And be sure you set the request type as multipart/form-data You can set it from postman in the headers tab.
If another object you need to send with multipart file,you can send it as a string and then you can convert it to object at the backend side.
@PostMapping("/upload")
public void uploadFile(@Nullable @RequestParam(value = "file",required = false) MultipartFile file,
@RequestParam(value = "input", required = false) String st)
{
ObjectMapper om = new ObjectMapper();
MyInput input = null;
try {
input = om.readValue(st, MyInput.class); //string st -> MyInput input
} catch (IOException e) {
e.printStackTrace();
}
}
Postman request example :