I have an issue using Ajax upload with Spring 3 MVC. I understand that I have to configure multipartResolver bean in spring config, which I've done. Than I can have controller like this
@RequestMapping(value ="/settingsSim")
@ResponseBody
public Map uploadSimSettings(@RequestParam(value="qqfile", required=true) MultipartFile settings) {
Map<String, Object> ret = new HashMap<String, Object>();
return ret;
}
The problem is that when I actually send the request to the server (actually valums Ajax file upload does this for me), I get an Internal server error response and nothing is shown in the logs. I am really scratching my head now, as I cannot figure out the problem.
@Tomas I encountered same issue while using the same jquery plugin. Please change the Content-Type in the plugin code to xhr.setRequestHeader("Content-Type", "multipart/form-data"); on my plugin its line 1203, after this its now showing a stack trace, however I am encountering another issue where the logs are printing : Sep 8, 2011 9:43:39 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet dispatcher threw exception org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
When using valums plugin I solved this problem by using
@RequestBody
Spring annotation. You could rewrite your code as follows:Note that the variable
body
will contain the contents of the uploaded file. Also there is no method declaration in your example which means that your method will be mapped to GET request.P.S. I also had this "no multipart boundary" problem when parsing request with Apache Commons.
HttpServletRequest#getParts()
returns just an empty collection.my solution:
As per my observation the file upload plugin does not send a multipart file but sends a stream. I could get it to work by declaring the controller method to accept filename as request param qqfile and the second parameter as httprequest. I then did further processing using request.getinputstream. Hope that helps!
Regards,
Pradyumna
I had the same problem with the fineuploader (valums), and I tried using request.getInputStream() but did not get it to work.
The @ResponseBody annotation worked but I got the whole body with headers. I thought processing that and stripping off the unwanted chunks was not very elegant. I looked further and found the solution is this post:
problem with spring ajax file upload
Like it is said, I added the bean configuration for the multipart resolver to my spring configuration
After that, I could easily retrieve my file using
Don't forget to add the Apache commons-io.jar and commons-fileupload.jar libraries in your project to get it to work