【发布时间】:2021-09-22 13:22:22
【问题描述】:
有一个 spring-mvc 控制器资源来接收文件并将它们存储在本地存储中。该请求是一个多部分(“Content-Type:multipart/form-data”),由几个部分组成。第一部分是文件的 JSON/XML 描述。第二个和以下是文件。但这些部分也可能是多部分的(“Content-Type: multipart/mixed”)。一小部分文件。多部分中的多部分。
POST /exampleAPI/nms/v1/myStore/tel%3A%2B19585550100/objects/operations/bulkCreation HTTP/1.1
Accept: application/xml
Authorization: BEARER 08776724-6d0d-4aa6-a404-2bc19b5cf903
Host: example.com
Content-Type: multipart/form-data; boundary="===============outer123456==";
Content-Length: nnnn
MIME-Version: 1.0
--===============outer123456==
Content-Type: application/xml
Content-Disposition: form-data; name=”root-fields”
<?xml version="1.0" encoding="UTF-8"?>
<nms:objectList xmlns:nms="urn:oma:xml:rest:netapi:nms:1">
<object>
<parentFolder>http://example.com/exampleAPI/nms/v1/myStore/tel%3A%2B19585550100/folders/fld123</parentFolder>
<attributes/>
<flags>
<flag>\Seen</flag>
<flag>\Flagged</flag>
</flags>
</object>
<object>
<parentFolderPath>/Pictures</parentFolderPath>
<attributes/>
<flags>
<flag>\Seen</flag>
</flags>
</object>
</nms:objectList>
--===============outer123456==
Content-Type: multipart/mixed; boundary=”--=-sep-=--”
Content-Disposition: form-data; name=”attachments”
----=-sep-=--
Content-Type: text/plain
Content-Disposition: attachment; filename=”body.txt”
See attached photo
----=-sep-=--
Content-Type: image/gif
Content-Disposition: attachment; filename="picture.gif"
GIF89a...binary image data...
----=-sep-=----
--===============outer123456==
Content-Type: multipart/mixed; boundary=”--=-sep-=--”
Content-Disposition: form-data; name=”attachments”
----=-sep-=--
Content-Type: text/plain
Content-Disposition: attachment; filename=”body.txt”
Photo from trip to Vancouver
----=-sep-=--
Content-Type: image/gif
Content-Disposition: attachment; filename="picture.gif"
GIF89a...binary image data...
----=-sep-=----
--===============outer123456==--
我必须根据请求结构将它们分组存储。 Body.txt 和picture.gif 来自一组中的第二个表单数据部分,来自另一组中的第三个表单数据的文件。但是使用 MultipartFile 或 Part 或 MultipartHttpServletRequest 没有关于嵌套的信息,所有文件都在一个级别上。
如何在层次结构中接收多部分数据?
@RestController
public class AttachmentController {
@PostMapping(path = ("/upload"), consumes = {"multipart/form-data", "multipart/mixed"})
public Response uploadFiles(
@RequestPart(value = "description") FilesDescription fileDesc,
@RequestPart(value = "attachments", required = false) List<MultipartFile> attachments) {
【问题讨论】:
标签: java spring-mvc multipart