0

I was fumbling to use RequestMethod.PUT (and RequestMethod.DELETE) as described in my previous question. At last the approach worked but when I designate a method with RequestMethod.PUT in my Spring controller, this method is called when the form is submitted but presumably it appears that the request is not regarded as a multipart request even though the form has that attribute enctype="multipart/form-data".

The form is as follows something similar to the previous question.

<form:form id="mainForm" name="mainForm" method="put" action="Temp.htm" enctype="multipart/form-data" commandName="tempBean">
    <input type="file" id="myFile" name="myFile"/>
    <input type="text" id="myText" name="myText"/>
    <input type="submit" id="btnSubmit" name="btnSubmit" value="Submit"/>
</form:form>

and the method in Spring which is invoked when a submit button is clicked is as follows.

@RequestMapping(method={RequestMethod.PUT}, value={"admin_side/Temp"}, headers={"content-type=multipart/form-data"})
public String update(@RequestParam("myText") String text, @ModelAttribute("tempBean") TempBean tempBean, BindingResult error, Map model, HttpServletRequest request, HttpServletResponse response)
{        
    System.out.println(ServletFileUpload.isMultipartContent(request)+"  :  "+text);
    return "admin_side/Temp";
}

Other request parameters are obtained like @RequestParam("myText") String text and even with request.getParameter("myText") but the the method invocation of ServletFileUpload.isMultipartContent(request) returns false (also request.getParameter("myFile") returns null) which means that the request doesn't appear to be a multipart request.

When the request method is changed to RequestMethod.POST, everything goes fine.

How to get multipart contents using the PUT method?

Community
  • 1
  • 1
Tiny
  • 27,221
  • 105
  • 339
  • 599
  • Looks a lot like your previous question http://stackoverflow.com/questions/13648599/how-to-upload-a-file-using-the-put-method-via-ajax-in-spring-mvc – Alex Barnes Dec 01 '12 at 18:21
  • That question is related to Ajax which is quite different. – Tiny Dec 01 '12 at 18:26
  • Confusing - I could obtain the file using `@RequestParam("myFile") MultipartFile file` as a method parameter in both the cases (PUT and POST) but `ServletFileUpload.isMultipartContent(request)` returns **true**, if the POST method is used and it returns **false**, if the PUT method is used. Can someone clarify about it? Doesn't PUT (or DELETE) have a multipart request even though the form's attribute `enctype="multipart/form-data"` is defined? – Tiny Dec 01 '12 at 21:27

0 Answers0