过大文件上传

简单整理,可能会有问题

1.
检查两个jar包(commons-fileupload,commons-io)

    commons-fileupload
    commons-fileupload
    1.3.3

2.
@RestControllerAdvice
public class AdviceController {
    // 对这个异常的统一处理,返回值 和Controller的返回规则一样
    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public Map 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;
    }

}

你可能感兴趣的:(过大文件上传)