美文网首页
过大文件上传

过大文件上传

作者: 呆弱鸡 | 来源:发表于2018-10-31 15:58 被阅读0次

    简单整理,可能会有问题

    1.
    检查两个jar包(commons-fileupload,commons-io)
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.3.3</version>
    </dependency>
    2.
    @RestControllerAdvice
    public class AdviceController {
        // 对这个异常的统一处理,返回值 和Controller的返回规则一样
        @ExceptionHandler(MaxUploadSizeExceededException.class)
        public Map<String, Object> handleAll() {
        
        }
    }
    3.
    import javax.servlet.MultipartConfigElement;
    import org.springframework.boot.web.servlet.MultipartConfigFactory;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.multipart.commons.CommonsMultipartResolver;
    
    @Configuration
    public class FileConfig {
    
        @Bean
        MultipartConfigElement multipartConfigElement() {
            MultipartConfigFactory factory = new MultipartConfigFactory();
            factory.setMaxFileSize(100000000);
            factory.setMaxRequestSize(100000000);
            factory.setFileSizeThreshold(100000000);
            return factory.createMultipartConfig();
        }
    
        @Bean
        public CommonsMultipartResolver multipartResolver() {
            CommonsMultipartResolver a = new CommonsMultipartResolver();
            a.setMaxUploadSize(10000000);
            return a;
        }
    
    }
    

    相关文章

      网友评论

          本文标题:过大文件上传

          本文链接:https://www.haomeiwen.com/subject/vvmatqtx.html