正在 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 中找到解析此消息的方法。
请注意,文件数量可能会有所不同。
我已经尝试使用 CommonsMultipartResolver
或 StandardServletMultipartResolver
,但两者都只支持 multipart/form-data
(rfc1867)。
除了自己编写解析器之外,Spring还有什么方法可以解析这些请求吗?
虽然这不是一个很好的解决方案,但它是我找到的唯一解决方案:
我基本上用 this class and then loaded it into the apache library with this simple subclass 或 CommonsMultipartResolver
重新实现了 ServletFileUpload
@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();
}
这是基于球衣的 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 中找到解析此消息的方法。
请注意,文件数量可能会有所不同。
我已经尝试使用 CommonsMultipartResolver
或 StandardServletMultipartResolver
,但两者都只支持 multipart/form-data
(rfc1867)。
除了自己编写解析器之外,Spring还有什么方法可以解析这些请求吗?
虽然这不是一个很好的解决方案,但它是我找到的唯一解决方案:
我基本上用 this class and then loaded it into the apache library with this simple subclass 或 CommonsMultipartResolver
ServletFileUpload
@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();
}
这是基于球衣的 spring 启动项目。