Spring MVC with ajax file upload and MultipartFile

后端 未结 5 1145
余生分开走
余生分开走 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:29

    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

     public @ResponseBody Map ajaxUploadFile(@RequestParam MultipartFile qqfile) { ... }
    

    Don't forget to add the Apache commons-io.jar and commons-fileupload.jar libraries in your project to get it to work

提交回复
热议问题