Multipart Config maximum file size not working in Tomcat 8

I have a POST API whose data multipart/form-data.

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response postEvent(@HeaderParam("id") String id, 
        @HeaderParam ("schema-version") String schemaVersion,
        byte[] serializedEvents)

I would like to limit the maximum size of the downloaded file to 64 KB.

So, I made the following change to webapps\<appName>\WEB-INF\web.xml

<multipart-config>
  <max-file-size>65536</max-file-size>
  <max-request-size>65536</max-request-size>
  <file-size-threshold>0</file-size-threshold>
</multipart-config>

But it does not seem to work. I also tried changing the connector maxPostSize parameter, although I know that it will only work for the case when I consume the body like application/x-www-form-urlencoded.

I use Tomcat 8.0 and Jersey as an implementation of Rest. Can anyone suggest where I'm wrong here?

Edit: here is a screenshot of the request:

enter image description here

And here is the part web.xml:

<servlet>
    <servlet-name>jersey-servlet</servlet-name>
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <multipart-config>
        <max-file-size>65536</max-file-size>
        <max-request-size>65536</max-request-size>
        <file-size-threshold>0</file-size-threshold>
    </multipart-config>
</servlet>
+4
source share

Source: https://habr.com/ru/post/1599873/


All Articles