在春天解析Multipart / mixed

时间:2017-05-18 00:31:03

标签: java spring http spring-mvc multipart

我想解析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&%--

此消息符合rfc1341,但我找不到在Spring中解析此方法的方法。

请注意,文件数量可能会有所不同。

我已尝试使用CommonsMultipartResolverStandardServletMultipartResolver,但两者都只支持multipart/form-datarfc1867)。

除了编写自己的解析器之外,有没有办法在Spring中解析这些请求?

2 个答案:

答案 0 :(得分:0)

虽然这不是一个非常好的解决方案,但它是我找到的唯一一个:

我基本上使用this class重新实现了ServletFileUpload,然后将其加载到CommonsMultipartResolver {{1}}

的apache库中

答案 1 :(得分:0)

    @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();
}

这是基于球衣的春季靴子项目。

相关问题