简体   繁体   English

在 Spring 中解析 Multipart/mixed

[英]Parsing Multipart/mixed in Spring

I want to parse requests like the following in my RestController我想在我的RestController解析如下请求

POST http://#.#.#.#:#/report HTTP/1.1
User-Agent: Android
Accept: text/html,application/xml,application/json,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Content-Type: multipart/mixed; boundary=%&REPORT_DIVIDER&%
Authorization: Basic ***
Content-Length: 23236
Host: #.#.#.#:#
Connection: Keep-Alive
Accept-Encoding: gzip


--%&REPORT_DIVIDER&%
Content-Type: application/json

{"content-excluded":true}
--%&REPORT_DIVIDER&%
Content-Disposition: attachment; filename="INSTALLATION"

Content-Type: application/octet-stream
609903cf-fcc0-460c-87db-958e031ac156
--%&REPORT_DIVIDER&%--

This message is conform to rfc1341 , yet I cannot find a way to parse this in Spring.此消息符合rfc1341 ,但我找不到在 Spring 中解析它的方法。

Note that the number of files may vary.请注意,文件数量可能会有所不同。

I've already tried using CommonsMultipartResolver or StandardServletMultipartResolver , but both only support multipart/form-data ( rfc1867 ).我已经尝试过使用CommonsMultipartResolverStandardServletMultipartResolver ,但都只支持multipart/form-data ( rfc1867 )。

Is there any way to parse these request in Spring besides writing my own parser?除了编写自己的解析器之外,还有什么方法可以在 Spring 中解析这些请求吗?

While it is not a very nice solution, it was the only one I found:虽然这不是一个很好的解决方案,但它是我发现的唯一一个:

I essentially reimplemented ServletFileUpload with this class and then loaded it into the apache library with this simple subclass of CommonsMultipartResolver我基本上用这个类重新实现了ServletFileUpload ,然后用这个简单CommonsMultipartResolver 子类将它加载到 apache 库中

    @Path("api")
    @PUT
    @Consumes("multipart/mixed")
    @Produces("multipart/mixed")
    public MultiPart twelve( MultiPart multiPart) throws IOException {

    List<BodyPart> bodyParts = multiPart.getBodyParts();
    BodyPartEntity bpe = (BodyPartEntity) bodyParts.get(1).getEntity();
}

This is for jersey based spring boot project.这是基于球衣的弹簧靴项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM