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 (592730896) exceeds the configured maximum (10485760)
因为springboot对于长传文件最大支持1M(也就是10485760 bytes),所以我们需要在yml配置文件中修改配置......话不多说直接上代码
yml配置文件中添加一下代码:
multipart:
maxRequestSize: 3072MB
maxFileSize: 3072MB
配置类如下:
package com.oumi.nas.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.MultipartConfigElement;
/**
* Created by 芦柑君
*
* @version 1.0
* @date 2021/9/7
* @describe
*/
@Configuration
public class MultipartConfig {
@Bean
public MultipartConfigElement multipartConfigElement(@Value("${multipart.maxFileSize}") String maxFileSize, @Value("${multipart.maxRequestSize}") String maxRequestSize) {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize(maxFileSize);
factory.setMaxRequestSize(maxRequestSize);
return factory.createMultipartConfig();
}
}