问题描述:

I have a POST API which consumer multipart/form-data data.

@POST

@Consumes(MediaType.MULTIPART_FORM_DATA)

public Response postEvent(@HeaderParam("id") String id,

@HeaderParam ("schema-version") String schemaVersion,

byte[] serializedEvents)

I wanted to limit the maximum uploaded file size to 64 KB.

So, I made the following change in 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 be working. I also tried changing the maxPostSize parameter of Connector, though, I know that will work only for case where I am consuming the body as application/x-www-form-urlencoded.

I am using Tomcat 8.0 and Jersey as Rest implementation. Can anyone please suggest where am I going wrong here?

Edit: Here is the screenshot of the request:

And, here is the part of 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>

相关阅读:
Top