user1050619
user1050619

Reputation: 20856

FileUploadBase$SizeLimitExceededException apache tomcat

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)

Upvotes: 24

Views: 57531

Answers (6)

Gunars Rodins
Gunars Rodins

Reputation: 11

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

Upvotes: 1

pserimer
pserimer

Reputation: 293

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

Upvotes: 2

Enamul Haque
Enamul Haque

Reputation: 5053

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 {

    }

Upvotes: 0

Daniel Mikusa
Daniel Mikusa

Reputation: 15006

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.

Upvotes: 7

Gene
Gene

Reputation: 11267

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>

Upvotes: 13

Jean Dok
Jean Dok

Reputation: 494

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

Upvotes: 26

Related Questions