Contents
  1. 1. Max Upload File Size in Nginx
    1. 1.1. The default max upload file size in Nginx
    2. 1.2. When over the max upload file size
    3. 1.3. Solutions
  2. 2. Max Upload File Size in Spring Framework
    1. 2.1. The default max upload file size in Spring
    2. 2.2. When over the max upload file size
    3. 2.3. Solutions

Max Upload File Size in Nginx

The default max upload file size in Nginx

The default maximum body size of a client request, or maximum file size, that nginx allows you to have, is 1M. So when you try to upload something larger than 1M, you get the following error: 413: Request Entity Too Large.

When over the max upload file size

When upload file over max size Nginx return

  • status code: 413 Request Entity Too Large

  • Content-Type: text/html

  • response body:

    1
    2
    3
    4
    5
    6
    7
    <html>
    <head><title>413 Request Entity Too Large</title></head>
    <body>
    <center><h1>413 Request Entity Too Large</h1></center>
    <hr><center>nginx/1.18.0</center>
    </body>
    </html>

Solutions

Add the following settings in your Nginx configuration file nginx.conf

1
2
3
4
http {
client_max_body_size 100M;
....
}

Max Upload File Size in Spring Framework

The default max upload file size in Spring

MultipartProperties‘ Properties

  • max-file-size specifies the maximum size permitted for uploaded files. The default is 1MB
  • max-request-size specifies the maximum size allowed for multipart/form-data requests. The default is 10MB.

When over the max upload file size

The Java web project will throw the IllegalStateException

1
2
3
4
5
6
 - UT005023: Exception handling request to /file/uploadFile
java.lang.IllegalStateException: io.undertow.server.handlers.form.MultiPartParserDefinition$FileTooLargeException: UT000054: The maximum size 1048576 for an individual file in a multipart request was exceeded
at io.undertow.servlet.spec.HttpServletRequestImpl.parseFormData(HttpServletRequestImpl.java:847)
at io.undertow.servlet.spec.HttpServletRequestImpl.getParameter(HttpServletRequestImpl.java:722)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:85)
...

Solutions

Add the following settings in your spring boot configuration file application.yml

1
2
3
4
5
6
7
spring:
servlet:
multipart:
# max single file size
max-file-size: 100MB
# max request size
max-request-size: 200MB
Contents
  1. 1. Max Upload File Size in Nginx
    1. 1.1. The default max upload file size in Nginx
    2. 1.2. When over the max upload file size
    3. 1.3. Solutions
  2. 2. Max Upload File Size in Spring Framework
    1. 2.1. The default max upload file size in Spring
    2. 2.2. When over the max upload file size
    3. 2.3. Solutions