How to limit multipart file upload size at jboss l

2019-04-15 17:12发布

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.

2条回答
我只想做你的唯一
2楼-- · 2019-04-15 17:37

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"/>
查看更多
走好不送
3楼-- · 2019-04-15 17:40

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> 
查看更多
登录 后发表回答