I am trying to upload a File with one parameter using spring 3.
This is my controller method which should enable this service:
@RequestMapping(value="/{id}", method = RequestMethod.PUT, headers="content-type=multipart/form-data")
public ResponseEntity<String> uploadImageWithJsonParamater(@PathVariable("id") Long id, @RequestParam String json, @RequestParam MultipartFile customerSignFile) {
//...
}
The problem is, that the server cannot dispatch to this method:
MissingServletRequestParameterException: Required String parameter ‘json’ is not present
If I change the RequestMethod from PUT to POST, everything is fine. So does anybody know the problem?
It seems that it isn’t allowed to transmit form-data via PUT.
I debugged a little bit and the following method returns false in the PUT case but true in the POST case:
public boolean isMultipart(HttpServletRequest request) {
return (request != null && ServletFileUpload.isMultipartContent(request));
}
I would appreciate any help!
Thanks in advance!
You can’t send form data via PUT as per the HTML standard. You can only send files via PUT, and in this case they’re send more efficiently then with POST (because you no longer have all the multi-part overhead), but in order for you PUT listening server side component to actually receive a file via PUT you have to make sure that you actually send a PUT command to it (via javascript for instance). Here’s an example that uses JQuery: