【问题标题】:Parsing Multipart/mixed in Spring在 Spring 中解析 Multipart/mixed
【发布时间】:2017-05-18 00:31:03
【问题描述】:

我想在我的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-data (rfc1867)。

除了编写自己的解析器之外,还有什么方法可以在 Spring 中解析这些请求?

【问题讨论】:

    标签: java spring http spring-mvc multipart


    【解决方案1】:

    虽然这不是一个很好的解决方案,但它是我发现的唯一一个:

    我基本上用this class 重新实现了ServletFileUpload,然后用this simple subclassCommonsMultipartResolver 将它加载到apache 库中

    【讨论】:

      【解决方案2】:
          @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();
      }
      

      这是基于球衣的弹簧靴项目。

      【讨论】:

        猜你喜欢
        • 2015-02-07
        • 2017-03-04
        • 2017-08-07
        • 2014-09-09
        • 2018-12-01
        • 2014-10-31
        • 2015-08-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多