How to limit multipart file upload size at jboss l

2019-04-15 17:45发布

问题:

My application is running on jboss AS7+RestEasy, currently I am handling file size limit in my APi as

@POST
@GZIP
@RequestFilter
@Produces("application/json")
@Consumes("multipart/form-data")
@Path("/demo/test")
public String uploadTest(
        @MultipartForm UPFile uploadFileFile,
        ) {
if (uploadFileFile.getFileSize() > 10*10*1024) {
//error.. 
}
}

Where I get fileSize as @FormParm, this works for me.

Issue is that uploadTest() this api gets called after file is uploaded to jboss container, and then it check for file size this takes unnecessarily server resources (Say client uploads 1GB data this data will be uploaded to server) I am looking for something that rejects files once they exceed size of 10MB.

回答1:

Adding this to your web.xml can help you.

 <multipart-config>  
          <max-file-size>5120000</max-file-size>  
          <max-request-size>5120000</max-request-size>  
        </multipart-config> 


回答2:

You can set the max-post-size attribute in the relevant connector in web subsystem.

<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" max-post-size="10485760"/>