具有resteasy和multipart / form-data请求的最大文件大小 [英] Max file size with resteasy and multipart/form-data request

查看:263
本文介绍了具有resteasy和multipart / form-data请求的最大文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用resteasy处理multipart / form-data请求时,如何控制最大文件大小和/或最大请求大小?

How can I control the max file size and/or the max request size when using resteasy to handle a multipart/form-data request ?

我的代码看起来像这个:

My code looks like this:

@POST
@Path("/somerestresource")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response handleForm(@MultipartForm MyForm form) {
    ...
}

使用Servlet我可以使用 @MultipartConfig 注释控制内容。

With a Servlet I can control stuff with the @MultipartConfig annotation.

所以我'考虑绕过resteasy并使用 @Context 注入 HttpServletRequest 并在web.xml中配置我的servlet但是我不确定副作用。

So I'm thinking about bypassing resteasy and using @Context to inject a HttpServletRequest and having my servlet configured inside the web.xml but I'm unsure of the side effects.

推荐答案

使用JAX-RS 2.0,您可以使用绑定到上传方法的ContainerRequestFilter使用 @NameBinding 注释。在此过滤器中,您将查看 content-length 请求标头,并在内容长度超过您计划接受的最大值时丢弃该请求( requestContext.abortWith(...)

With JAX-RS 2.0, you could use a ContainerRequestFilter bound to your upload method using a @NameBinding annotation. In this filter, you would look at the content-length request header and discard the request if the content length exceeds the maximum value you plan to accept (requestContext.abortWith(...))

使用JAX-RS 1.1和RESTEasy,你可以使用PreProcessInterceptor做同样的事情( http://docs.jboss.org/resteasy /docs/1.1.GA/userguide/html/Interceptors.html#PreProcessInterceptors )并遵循类似于上述逻辑逻辑的逻辑逻辑。

With JAX-RS 1.1 and RESTEasy, you could probably do the same thing using a PreProcessInterceptor (http://docs.jboss.org/resteasy/docs/1.1.GA/userguide/html/Interceptors.html#PreProcessInterceptors) and follow a logic logic similar to the one described above.

这篇关于具有resteasy和multipart / form-data请求的最大文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆