本文介绍了我正在尝试设置maxFileSize,但不兑现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JHipster开发应用程序.我已经在我的application-dev.yml文件中添加了以下内容:

I am developing an application utilizing JHipster. I have added the following to my application-dev.yml file:

spring:

    profiles:
        active: dev

    multipart:
        maxFileSize: -1

但是,当我尝试上载大于1MB的文件时,仍然出现错误:

But I am still getting an error when I try to try to upload a file > 1MB:

Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (20663006) exceeds the configured maximum (10485760)

我想念什么?看来这应该很简单.

What am I missing? It seems this should be pretty straight forward.

更新1

我按照Andy的建议从spring配置取消了嵌套,但仍然收到错误.更新的yml文件:

I un-nested it from spring config as suggested by Andy, but still got the error. Updated yml file:

server:
    port: 8080

multipart:
        maxFileSize: -1

spring:

    profiles:
        active: dev

    datasource: ...

更新2

在较新版本的Sprint Boot中再次遇到此问题,必须更改为:

Ran into this issue again on newer version of Sprint Boot and had to change to this:

spring:
    http:
        multipart:
            max-file-size: 30MB
            max-request-size: 30MB

推荐答案

除了配置最大文件大小外,如果单个文件大于10MB或要上传多个文件,则可能还需要配置最大请求大小.同一请求中的文件大小总计超过10MB.

In addition to configuring max file size, you may also need to configure max request size if you have a single file that's greater than 10MB or you want to upload multiple files in the same request with sizes that total more than 10MB.

需要使用的确切属性取决于您使用的Spring Boot的版本,因为它们在1​​.4中进行了更改:

The exact properties that need to be used depend on the version of Spring Boot that you are using as they changed in 1.4:

  • multipart.maxFileSize
  • multipart.maxRequestSize
  • multipart.maxFileSize
  • multipart.maxRequestSize
  • spring.http.multipart.maxFileSize
  • spring.http.multipart.maxRequestSize
  • spring.http.multipart.maxFileSize
  • spring.http.multipart.maxRequestSize
  • spring.servlet.multipart.maxFileSize
  • spring.servlet.multipart.maxRequestSize
  • spring.servlet.multipart.maxFileSize
  • spring.servlet.multipart.maxRequestSize

这篇关于我正在尝试设置maxFileSize,但不兑现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 07:06