FileUploadBase$SizeLimitExceededException apache tomcat
Asked Answered
C

6

24

Im trying to upload file from a JSP file and I get the following error in catalina.out. As specified in many blogs, I increased the the max-file-size under webapps/manager/WEB-INF/web.xml but still I have the same problem...Where should I increase it to resolve this error?

<multipart-config>
      <!-- 50MB max -->
      <max-file-size>5242880000000</max-file-size>
      <max-request-size>5242880000000</max-request-size>
      <file-size-threshold>0</file-size-threshold>
    </multipart-config>

org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (341297) exceeds the configured maximum (51200)
Carrousel answered 10/9, 2014 at 20:57 Comment(0)
X
26

I had the same problem. I solved it by setting the parameter maxPostSize in the http server tomcat connector located in <tomcat-root-folder>/conf/server.xml as follows:

<Connector connectionTimeout="20000" 
           port="8080" 
           protocol="HTTP/1.1" 
           redirectPort="8443" 
           maxPostSize="52428800" />

Set maxPostSize to 52428800 increase the upload file size to 50 MB. By default it's set to 2 MB.

For more explanation, read this: https://tomcat.apache.org/tomcat-7.0-doc/config/http.html

Xeroderma answered 2/8, 2015 at 8:19 Comment(0)
K
13

https://maxrohde.com/2011/04/27/large-war-file-cannot-be-deployed-in-tomcat-7/

Go to the web.xml of the manager application (for instance it could be under /tomcat7/webapps/manager/WEB-INF/web.xml. Increase the max-file-size and max-request-size:

<multipart-config>
<!– 50MB max –>
<max-file-size>52428800</max-file-size>
<max-request-size>52428800</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
Kistna answered 1/5, 2018 at 20:18 Comment(0)
F
7

This is configured in web.xml for the manager app.

Ex:

  <servlet>
    <servlet-name>HTMLManager</servlet-name>
    <servlet-class>org.apache.catalina.manager.HTMLManagerServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <multipart-config>
      <!-- 50MB max -->
      <max-file-size>52428800</max-file-size>
      <max-request-size>52428800</max-request-size>
      <file-size-threshold>0</file-size-threshold>
    </multipart-config>
  </servlet>

https://github.com/apache/tomcat/blob/7.0.x/webapps/manager/WEB-INF/web.xml#L56-L57

The manager app uses the Servlet 3.0 API. If you're using commons file upload directly, it's up to you and you need to configure this manually.

Ferrochromium answered 15/9, 2014 at 16:23 Comment(5)
find webapps/manager/WEB-INF/web.xml, edit max-file-size and max-request-size to anything you need.Bohol
The Url is BrokenDahna
Fixed URL. ThanksFerrochromium
What do you do when webapps/manager doesn't exist?Geothermal
The question was asked in reference to the Manager application that comes with Tomcat, so the instructions are to update the max allowed size in the web.xml for the manager app. If you're seeing this issue in a different app, then adjust the web.xml for your app. If you do not have a web.xml, see https://mcmap.net/q/546801/-fileuploadbase-sizelimitexceededexception-apache-tomcat.Ferrochromium
G
1

If you are using Spring MultipartResolver, find the bean and change it's maxUploadSize property.

`<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
   <property name="maxUploadSize" value="52428800" />
 </bean>`

Given code sets the upload file size to 50 MB

Gavial answered 2/11, 2021 at 6:34 Comment(0)
A
0

you can use in Servlet like bellow

    @WebServlet(name = "RemittanceDocApi", urlPatterns = {"/RemittanceDocApi"})
    @MultipartConfig(fileSizeThreshold = 1024 * 1024 * 2, // 2MB
    maxFileSize = 1024 * 1024 * 10, // 10MB
    maxRequestSize = 1024 * 1024 * 50)   // 50MB
    public class RemittanceDocApi extends HttpServlet {

    }
Appraisal answered 28/12, 2020 at 6:18 Comment(0)
E
0

If you get hit limit from a spring microservice (internally tomcat, but no web.xml):

Maximum upload size exceeded; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.impl.SizeLimitExceededException: the request was rejected because its size (26025118) exceeds the configured maximum (25165824)

Apply for microservice launch parameters (500MB upload per file limit):

  -spring.servlet.multipart.max-file-size=500MB
  -spring.servlet.multipart.max-request-size=500MB
Electoral answered 24/10, 2023 at 14:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.