Spring MVC with ajax file upload and MultipartFile

后端 未结 5 1160
余生分开走
余生分开走 2021-01-06 13:15

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 control

5条回答
  •  忘掉有多难
    2021-01-06 13:37

    When using valums plugin I solved this problem by using @RequestBody Spring annotation. You could rewrite your code as follows:

    @RequestMapping(value ="/settingsSim",method=RequestMethod.POST)
    @ResponseBody
    public Map uploadSimSettings(@RequestBody String body) {
     /*
     some controller logic 
     */
    }
    

    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.

提交回复
热议问题