org.springframework.web.multipart.MaxUploadSizeExceededException

报错:

org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (10935680) exceeds the configured maximum (10485760)

分析:

spring boot 内置tomcat默认的上传文件大小为:1M

 

方案一:

在配置文件中加以下参数

spring:
  servlet:
    multipart:
      max-file-size: 100MB # 单个文件大小
      max-request-size: 100MB # 设置总上传的数据大小
      enabled: true #开启

方案二:

在启动application类中添加以下代码

 /**
     * 文件上传配置
     * @return
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //文件最大
        factory.setMaxFileSize("100MB"); //KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize("100MB");
        return factory.createMultipartConfig();
    }

 

你可能感兴趣的:(异常)