Multipart transferTo looks for a wrong file address when using createTempFile

后端 未结 3 923
灰色年华
灰色年华 2021-01-22 01:04

I have the following java code in Spring framework to convert a multipart file to a regular file:

    public static File convertToFile(MultipartFile multipart) {         


        
3条回答
  •  旧巷少年郎
    2021-01-22 01:06

    I solved the same issue by adding apache Commons FileUpload component. Hope it helps for you.

    1. add pom dependency
        
        
          commons-fileupload
          commons-fileupload
          1.3.3
        
    
    1. add resolver to spring mvc configuration
        @Bean(name = "multipartResolver")
        public CommonsMultipartResolver multipartResolver() {
            CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
            multipartResolver.setMaxUploadSize(100000);
            return multipartResolver;
        }
    

提交回复
热议问题