字段uploadFile超过

时间:2018-08-13 06:53:18

标签: spring-boot

我正在尝试使用SpringBoot从客户端发送Excel,但是获取文件时出现错误。我最多添加10MB或300MB的媒体资源,但该媒体资源无法运行。

  

org.apache.tomcat.util.http.fileupload.FileUploadBase $ FileSizeLimitExceededException:   字段uploadFile超过其最大允许大小1048576   个字节。         在org.apache.tomcat.util.http.fileupload.FileUploadBase $ FileItemIteratorImpl $ FileItemStreamImpl $ 1.raiseError(FileUploadBase.java:630)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:135)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在java.io.FilterInputStream.read(未知来源)〜[na:1.8.0_171]         在org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:98)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:68)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:293)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.catalina.connector.Request.parseParts(Request.java:2869)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.catalina.connector.Request.parseParameters(Request.java:3216)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.catalina.connector.Request.getParameter(Request.java:1137)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:381)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:75)   〜[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]         在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)   〜[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]         在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)   〜[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]         在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)   〜[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]         在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)   〜[tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)   [tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)   [tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)   [tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)   [tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)   [tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)   [tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)   [tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)   [tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:790)   [tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1459)   [tomcat-embed-core-8.5.27.jar:8.5.27]         在org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)   [tomcat-embed-core-8.5.27.jar:8.5.27]         在java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)[na:1.8.0_171]         在java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)[na:1.8.0_171]         在org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)   [tomcat-embed-core-8.5.27.jar:8.5.27]         在java.lang.Thread.run(未知来源)[na:1.8.0_171]

我的pom.xml

在我的pom.xml中,我具有版本1和1.15.10发行版

   <groupId>tutorial</groupId>
    <artifactId>tutorial</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <name>tutorial</name>
    <description>Demo project for tutorial CRUD</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

我在application.properties中添加了……什么都没有。

maxFileSize: 300Mb
maxRequestSize: 300Mb

编辑: 但是我可以从SpringBoot下载此文件。但是我无法发送此文件以读取内容

1 个答案:

答案 0 :(得分:2)

您需要设置其他属性以增加上传大小:

spring.http.multipart.max-file-size=1Mb
spring.http.multipart.max-request-size=10Mb

顺便说一句:Spring Boot 2的前缀已更改。在这里spring.servlet。但是,由于您使用的是1.5,因此以上所述对您都适用。

Spring Boot 2也有出色的教程:https://spring.io/guides/gs/uploading-files/