项目场景:
springboot集成minio报错:
使用minio上传大文件(图片等),会报超出显示异常
2024-04-25 16:36:33.286 ERROR 26060 — [nio-4000-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field uploadFile exceeds its maximum permitted size of 1048576 bytes.] with root cause
org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field uploadFile exceeds its maximum permitted size of 1048576 bytes.
at org.apache.tomcat.util.http.fileupload.impl.FileItemStreamImpl$1.raiseError(FileItemStreamImpl.java:114) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:135) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
问题描述
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/bd2310fc0db94fb38d78d396f371fbb9.png
原因分析:
提示:这里填写问题的分析:
首先根据报错,判断是文件上传超过最大的限制。追踪到我的minio工具类中
/**
* 上传文件
*/
public void uploadFile(InputStream inputStream, String bucket, String objectName) throws Exception {
minioClient.putObject(PutObjectArgs.builder().bucket(bucket).object(objectName)
.stream(inputStream, -1, 5242889L).build());
}
可以看到我配置了最大是5MB,但我上传的文件是4MB还是报错了!这是为什么呢?
解决方案:
问题解决:问题可能不在 MinIO 本身,而是在 Tomcat 或 Spring Boot 的配置上限制了上传的大小。
配置yml文件
添加这些配置
spring:
servlet:
multipart:
max-file-size: 200MB
max-request-size: 200MB
可以看到问题解决啦