4

I need to set max filesize for uploaded files in my servlet running on tomcat. I tried multipart config which worked on jetty, but tomcat just ignored it. It means deployment on tomcat server caused even big files can be uploaded. My configuration:

<servlet>
    <servlet-name>myServlet</servlet-name>
    <servlet-class>sk.test.MyServlet</servlet-class>
    <multipart-config>
        <max-file-size>1048576</max-file-size>
        <max-request-size>104857600</max-request-size>
    </multipart-config>
</servlet>

I already tried annotated configuration, which didnt work too.

Using: Tomcat 7.0.54, Servlet 3.0

I will appreciate any help, thanks

somtomas
  • 163
  • 1
  • 2
  • 6
  • have you checked this? http://stackoverflow.com/questions/2947683/httprequest-maximum-allowable-size-in-tomcat – Guy Bouallet Feb 17 '15 at 15:26
  • To Stefan: There is no exception. Tomcat just ignore configuration and let files be uploaded. To Guy: They speak about two possible ways of limitation in that thread, where i use the second one, however it does not work for me. – somtomas Feb 17 '15 at 15:36

1 Answers1

4

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

Vy Do
  • 46,709
  • 59
  • 215
  • 313