【问题标题】:How to solve RequestTooBigException, connection terminated as request was larger than 10485760?如何解决 RequestTooBigException,连接因请求大于 10485760 而终止?
【发布时间】:2018-10-07 08:39:38
【问题描述】:

我正在尝试将一个 6MB 的文件上传到我的 JHipster 应用服务器。但是,我收到以下错误。在哪里可以找到相关配置?

io.undertow.server.RequestTooBigException: UT000020: Connection terminated as request was larger than 10485760
at io.undertow.conduits.FixedLengthStreamSourceConduit.checkMaxSize(FixedLengthStreamSourceConduit.java:168)
at io.undertow.conduits.FixedLengthStreamSourceConduit.read(FixedLengthStreamSourceConduit.java:229)
at org.xnio.conduits.ConduitStreamSourceChannel.read(ConduitStreamSourceChannel.java:127)
at io.undertow.channels.DetachableStreamSourceChannel.read(DetachableStreamSourceChannel.java:209)
at io.undertow.server.HttpServerExchange$ReadDispatchChannel.read(HttpServerExchange.java:2332)
at org.xnio.channels.Channels.readBlocking(Channels.java:294)
at io.undertow.servlet.spec.ServletInputStreamImpl.readIntoBuffer(ServletInputStreamImpl.java:192)
at io.undertow.servlet.spec.ServletInputStreamImpl.read(ServletInputStreamImpl.java:168)
at io.undertow.server.handlers.form.MultiPartParserDefinition$MultiPartUploadHandler.parseBlocking(MultiPartParserDefinition.java:213)
at io.undertow.servlet.spec.HttpServletRequestImpl.parseFormData(HttpServletRequestImpl.java:792)

【问题讨论】:

  • 您使用的是哪个 servlet 容器?
  • 我使用Tomcat作为servlet容器
  • 真的吗? JHipster 应用程序使用嵌入式 Undertow,如您的堆栈所示。

标签: spring spring-boot jhipster


【解决方案1】:

除了 maslbl4 答案,对于像我这样使用“.yml”配置文件的人,使用以下代码:

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

对我来说效果很好。

【讨论】:

    【解决方案2】:

    对于 Spring Boot 1.5.13.RELEASE,试试这个属性:

    spring.http.multipart.max-request-size=100MB
    spring.http.multipart.max-file-size=100MB
    

    【讨论】:

      【解决方案3】:

      在容器级别,可以直接在连接器上指定属性maxPostSize

      来自文档:

      将由容器 FORM URL 参数解析处理的 POST 的最大大小(以字节为单位)。可以通过将此属性设置为小于或等于 0 的值来禁用此限制。如果未指定,则此属性设置为 2097152(2 兆字节)。

      【讨论】:

      • 是否可以向用户返回消息?
      【解决方案4】:

      Spring Boot 具有以下默认属性

      spring.servlet.multipart.max-file-size=1MB # Max file size. Values can use the suffixes "MB" or "KB" to indicate megabytes or kilobytes, respectively.
      spring.servlet.multipart.max-request-size=10MB # Max request size. Values can use the suffixes "MB" or "KB" to indicate megabytes or kilobytes, respectively.
      

      10485760 = 10MB

      见文件上传Spring Bootguide

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-03
        • 2019-07-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多