在其他Servlet过滤器中解决多部分请求而不会丢失上传内容
我的过滤器检查了多个部分的帖子,并可能在到达实际端点之前拒绝它们(球衣,在我的控件之外)。允许休闲多部分解析(如下所示)解决了例外:由于未提供
自定义的CommonSmultipartresolver或现有的分辨率工作,因此无法处理零件,因为在设置属性时,没有错误。但是,访问 /解决之后,内容会丢失。
我可以使用自定义的CommonSmultipartresolver并处理此处建议的丢失信息:在Spring Filter中解析Multipart/Form-DATA请求。但是,我希望在不复制请求的情况下提供一个清洁的解决方案,添加过滤器。
My Filter inspects multi-part posts and potentially rejects them before they reach the actual endpoint (jersey, outside my control). Allowing casual multipart parsing (as shown in answer below) solves the exception: Unable to process parts as no multi-part configuration has been provided
A custom CommonsMultipartResolver or the existing resolver work without the error when the property is set. However, the content gets lost after accessing / resolving it.
I could use a custom CommonsMultipartResolver and deal with the lost information as suggested here: Resolving multipart/form-data request in spring filter. However, I am hoping for a cleaner solution adding the filter, without copying the request.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要启用
允许casualmultipartparsing
tomcat上下文
,您可以注入自定义
tomcatservletwebserverfactory
进入您的应用程序(Spring Boot 2):
对于Spring Boot 1,工厂类是
tomcatembedservedservletcontainerfactory
。To enable the
allowCasualMultipartParsing
property of the TomcatContext
,you can inject a custom
TomcatServletWebServerFactory
into your application (Spring Boot 2):
For Spring Boot 1, the factory class is
TomcatEmbeddedServletContainerFactory
.查看其余问题(或“我希望有一个更清洁的解决方案添加过滤器,而无需复制请求”),我严重怀疑是否有一个。
该请求仅通过网络发送一次。它包含多个数据,一旦消耗了此信息(即从流中读取)流现在如何通过完整的数据转发到下一个处理器?
我猜这就是通用解决方案只会收到整个数据,决定将其转发到哪里,然后发送整个数据。如果不存储两者之间的数据,它将无法使用,它标记为“复制请求”。
Looking at the remainder of the question (or 'I am hoping for a cleaner solution adding the filter, without copying the request'), I seriously doubt there is one.
The request is sent over the network once only. It contains multipart data, and once this is consumed (i.e. read from the stream) how would the stream now get forwarded to the next processor with the complete data?
That's where I guess generic solutions just receive the whole data, decide where to forward it to and then send the whole data. It will not work without having stored the data inbetween, what is labelled as 'copying the request' by you.