首页 > 编程语言 >nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.Fil

nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.Fil

时间:2023-04-02 17:15:50浏览次数:40  
标签:fileupload java nested util catalina file apache org ApplicationFilterChain

一、问题背景

利用springboot上传大文件

二、报错截图如下

2023-04-02 16:04:18,681 ERROR [http-nio-63050-exec-6][GlobalExceptionHandler.java:58] - 系统异常:Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.
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 file exceeds its maximum permitted size of 1048576 bytes.
	at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.handleParseFailure(StandardMultipartHttpServletRequest.java:122)
	at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:115)
	at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:88)
	at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:87)
	at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1178)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1012)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:888)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.
	at org.apache.catalina.connector.Request.parseParts(Request.java:2939)
	at org.apache.catalina.connector.Request.getParts(Request.java:2797)
	at org.apache.catalina.connector.RequestFacade.getParts(RequestFacade.java:1098)
	at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:95)
	... 43 more
Caused by: org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.
	at org.apache.tomcat.util.http.fileupload.impl.FileItemStreamImpl$1.raiseError(FileItemStreamImpl.java:114)
	at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76)
	at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:135)
	at java.io.FilterInputStream.read(FilterInputStream.java:107)
	at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:98)
	at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:291)
	at org.apache.catalina.connector.Request.parseParts(Request.java:2895)
	... 46 more
三、我的项目配置如下

springboot版本是2.2.6.RELEASE,前端设置的限制是5M

四、分析问题

1、springboot 上传的默认文件限制大小是1M

public MultipartConfigElement createMultipartConfig() {
	long maxFileSizeBytes = this.convertToBytes(this.maxFileSize, -1);
	long maxRequestSizeBytes = this.convertToBytes(this.maxRequestSize, -1);
	long fileSizeThresholdBytes = this.convertToBytes(this.fileSizeThreshold, 0);
	return new MultipartConfigElement(this.location, maxFileSizeBytes, maxRequestSizeBytes, (int)fileSizeThresholdBytes);
}

2、根据错误日志,在LimitedInputStream打个断点

private void checkLimit() throws IOException {
	if (this.count > this.sizeMax) {
		this.raiseError(this.sizeMax, this.count);
	}
}
五、问题原因

springboot 默认上传文件的大小限制是1MB

六、解决方式

修改工程yaml配置

spring:
  servlet:
    multipart:
      max-file-size: 50MB
      max-request-size: 50MB

标签:fileupload,java,nested,util,catalina,file,apache,org,ApplicationFilterChain
From: https://www.cnblogs.com/fyusac/p/17280776.html

相关文章

  • Hadoop报错只no such file or drector exist.
    场景:在运行bin.hdfsdfs-mkdirXXXXXXXXX的命令的时候报此路径或者文件不存在。   解决办法:hadoopfs-mkdir-p/user/hadoop/TRANSLATEwithxEnglishArabicHebrewPolishBulgarianHindiPortugueseCatalanHmongDawRomanianChi......
  • An Error Ocurred - Error loading password's vault file ---Uninstall MySQL for Ex
    还是在2020年疫情封控开始前后的连续几个月天天重温Delphi、MSSQL、也偶尔折腾一下MySQL,最近2年都没再折腾,昨天2023.4.1,打开Excel是提示此此问题:卸载掉MySQLforExcel之后,再次打开Office2016就Ok了,奇怪为什么会出现这个问题呢 //点击showdetails之后如下:     ......
  • JS二进制文件转换:File、Blob、Base64、ArrayBuffer
    文件类型JS提供了一些API来处理文件或原始文件数据,例如:File、Blob、FileReader、Base64、ArrayBuffer、Canvas等。图源:知乎-前端充电宝类型说明BlobBlob对象表示一个不可变、原始数据的类文件对象。Blob表示的不一定是JavaScript原生格式的数据。File接口基于Blob......
  • DockerFile
    DockerFile构建镜像首先通过一张图来了解Docker镜像、容器和Dockerfile三者之间的关系。通过上图可以看出使用Dockerfile定义镜像,运行镜像启动容器。Dockerfile概念Docker镜像是一个特殊的文件系统,除了提供容器运行时所需的程序、库、资源、配置等文件外,还包含了一些......
  • makefile使用总结(一)
    本文参考《跟我一起写Makefile》编写,并做了一些适合个人习惯的修改,稍加总结而成。 首先提出的问题是:什么是makefile?为什么要用makefile?如何使用makefile?为了回答这三个问题,下面就围绕这些问题做一些记录。什么是makefile?简单点说makefile是一个描述了整个工程的编译规......
  • makefile 编写规则
    (一)makefile规则 一般开头都是Tab,不能空格,include前面不能是Tab;1、如果没编译过,将所有的 (.c)文件编译并且链接;2、如果有其中的(.c)文件改变,编译并链接改变的文件;3、如果(.h)文件被修改,编译引用相应的(.c)文件,链接;4、在随意修改时间的情况下,会导致编......
  • The following untracked working tree files would be overwritten by merge错误的
    问题描述只要云端代码更新,我的本地那里没有跟上云端的更新速度,就会出现这个错误:问题解决在Git终端里面,输入gitclean-d-f"出现错误的那个文件路径(就是错误显示的那一串)"然后Enter,会显示Removing了那个文件,然后再输入gitpull,显示这个:然后就等待它更新完成就行了。然后......
  • Linux设备文件三大结构:inode,file,file_operations
    structinodeLinux中一切皆文件,当我们在Linux中创建一个文件时,就会在相应的文件系统创建一个inode与之对应,文件实体和文件的inode是一一对应的,创建好一个inode会存在存储器中,第一次open就会将inode在内存中有一个备份,同一个文件被多次打开并不会产生多个inode,当所有被打开的文件......
  • YRCloudFile V6.10.0 功能新增对 NVIDIA GPUDirect 与回收站的支持
    近日,焱融科技发布分布式文件存储产品YRCloudFile V6.10.0版本。在该版本中,YRCloudFile首次支持了NVIDIAGPUDirectStorage(GDS)、新增回收站、数据加载热层清理等产品......
  • 【应用服务 App Service】App Service For Windows 如何挂载Storage Account File Sha
    问题描述很早之前,介绍了在AppServiceforLinux中挂载StorageAccount共享文件,当时Windows无法实现这个功能。而现在,AppServiceForWindows也可以挂载StorageAccount......