簡體   English   中英

在 Spring 中解析 Multipart/mixed

[英]Parsing Multipart/mixed in Spring

我想在我的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 中解析這些請求嗎?

雖然這不是一個很好的解決方案,但它是我發現的唯一一個:

我基本上用這個類重新實現了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();
}

這是基於球衣的彈簧靴項目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM