0

I tried various permutation an combination and googled as well,when I am uploading xsl file with multiplesheet i am getting following Exception-

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: Stream closed] with root cause java.io.IOException: Stream closed

Below is my code-

    <form name="upload" th:action="@{/util/uploadExcel}" action="/util/uploadExcel" enctype="multipart/form-data" method="post">
     <input type="file" name="fileData"  path="fileData"  />
     <input type="submit"/>
    </form>

    @Controller
    @RequestMapping("/util")
    public class UtilController {

    @RequestMapping(value=("/uploadExcel"),headers=("content-type=multipart/*"),method= RequestMethod.POST)
    public ModelAndView uploadExcel(@RequestParam("fileData") CommonsMultipartFile file,BindingResult result) {
        utilService.uploadData(file);
        ModelAndView modelAndView = new ModelAndView("paidAnalysis/index");
        return modelAndView;
    }


    @Bean
    public CommonsMultipartResolver multipartResolver() {
        return new CommonsMultipartResolver();
    }

}

MoreOver I have added dependency for 'commons-fileupload' in my project.

When I upload any csv file other than xsl I am getting-

There was an unexpected error (type=Bad Request, status=400). Required CommonsMultipartFile parameter 'fileData' is not present

3
  • @BalusC my pleasure you seen this,I am struck with this last couple of hours,please show me path to move forward Commented Jul 10, 2016 at 14:44
  • Accept RequestParam as MultipartFile instead of CommonsMultipartFile. It will work. Commented Jul 10, 2016 at 15:23
  • I have tried with both :( Commented Jul 10, 2016 at 15:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.