过大文件上传

2018-10-31  本文已影响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;
    }

}
上一篇下一篇

猜你喜欢

热点阅读