Httprequest Maximum Allowable Size in Tomcat

HttpRequest maximum allowable size in tomcat?

The connector section has the parameter

maxPostSize

The maximum size in bytes of the POST which will be handled by the container FORM URL parameter parsing. The limit can be disabled by setting this attribute to a value less than or equal to 0. If not specified, this attribute is set to 2097152 (2 megabytes).

Another Limit is:

maxHttpHeaderSize The maximum size of the request and response HTTP header, specified in bytes. If not specified, this attribute is set to 4096 (4 KB).

You find them in

$TOMCAT_HOME/conf/server.xml

How to upload files over 100 MB to Tomcat

Have a look at the documentation. In particular, you're interested in the maxFileSize parameter, which you can set either with annotations or xml.

Directly from the link above,

@MultipartConfig(location="/tmp", fileSizeThreshold=1024*1024,
maxFileSize=1024*1024*5, maxRequestSize=1024*1024*5*5)

or

<multipart-config>
<location>/tmp</location>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>

So for example, you can annotate your servlet like so:

@MultipartFileConfig( options )
public class YourServlet extends HttpServlet {

...

or add the equivalent xml in the config if using xml.

how to limit uploaded filesize in tomcat servlet

Set value of max file size, use annotation before servlet class or web.xml config.
See maxFileSize in annotation or <max-file-size></max-file-size> in xml config.

@MultipartConfig(
location="/tmp",
fileSizeThreshold=1024*1024, // 1 MB
maxFileSize=1024*1024*5, // 5 MB
maxRequestSize=1024*1024*5*5 // 25 MB
)

or

<multipart-config>
<location>/tmp</location>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>

Reference: https://docs.oracle.com/javaee/7/tutorial/servlets011.htm

Increase HTTP Post maxPostSize in Spring Boot

Found a solution. Add this code to the same class running SpringApplication.run.

// Set maxPostSize of embedded tomcat server to 10 megabytes (default is 2 MB, not large enough to support file uploads > 1.5 MB)
@Bean
EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
return (ConfigurableEmbeddedServletContainer container) -> {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
tomcat.addConnectorCustomizers(
(connector) -> {
connector.setMaxPostSize(10000000); // 10 MB
}
);
}
};
}

Edit: Apparently adding this to your application.properties file will also increase the maxPostSize, but I haven't tried it myself so I can't confirm.

multipart.maxFileSize=10Mb # Max file size.
multipart.maxRequestSize=10Mb # Max request size.


Related Topics



Leave a reply



Submit