Java Web Max Upload File Size Settings

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 uploading a file over max size, Nginx returns

  • status code: 413 Request Entity Too Large

  • Content-Type: text/html

  • response body:

    <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 to your Nginx configuration file nginx.conf

http {
client_max_body_size 100M;
....
}

Reload the Nginx configurations

$ nginx -s reload

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

 - 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

spring:
servlet:
multipart:
# max single file size
max-file-size: 100MB
# max request size
max-request-size: 200MB