I have created a controller:
@RequestMapping(value = "/photo/" , method = RequestMethod.POST)
public @ResponseBody
void addPhotoData(@RequestBody Photo photo, @RequestParam("data")
MultipartFile photoData) {
InputStream in = null;
try {
in = photoData.getInputStream();
photoService.save(photo, in);
} catch (IOException e) {
e.printStackTrace();
}
}
and I send the request with Postman:
I cannot understand why I receive the error 415 not supported. Help!
Try wrapping the request body into an object.
public class Payload {
private String name;
private String url;
private MultipartFile data;
...
}
Add consumes = { "multipart/form-data" }
and
@RequestMapping(value = "/photo/" , method = RequestMethod.POST, consumes = { "multipart/form-data" })
public @ResponseBody void addPhotoData(@ModelAttribute Payload payload) {
...
}
There is also MediaType.MULTIPART_FORM_DATA_VALUE
constant instead of using that string
This is called multipart mixed type. Try changing your signature like this
@RequestMapping(value = "/photo/" , method = RequestMethod.POST, consumes = {"multipart/mixed"})
public @ResponseBody void addPhotoData(@RequestPart Photo photo, @RequestPart("data")
MultipartFile photoData) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With