I Have a Controller like this:
@RequestMapping(value = "/user/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public UserLesserDTO createUser(@RequestParam("profileImageFile") MultipartFile file, @RequestBody UserDTO user, @PathVariable("method") String method) {
// Save profileImage as a profile image and store the image file name in user's profileImage attribute.
// save user.
}
and I have a HTML form with all user's attributes as <input type="text" name="user attribute name">
plus one <input type="file" name="profileImageFile">
I've receiving an error 415 like: The origin server is refusing to service the request because the payload is in a format not supported by this method on the target resource.
but when I remove @RequestBody UserDTO user
from my createUser()
method's signature the upload file part starts to work and I can get the file.
Already read this and this to set a data binder.
@InitBinder
public void initBinder(WebDataBinder binder, WebRequest request) {
binder.setDisallowedFields("user.profileImage");
binder.setAllowedFields("profileImageFile");
}
But this changes nothing.