【发布时间】:2016-03-20 10:15:58
【问题描述】:
我正在开发一项服务(前端和后端),该服务允许将多个文件和元数据上传到每个文件,因此我将能够生成保存文件的特定路径。 (元数据会给我关于路径的所有信息)。此外,请求将包含需要保存到数据库的信息(这部分工作正常),所以它都是事务性的。所以我唯一想不通的是如何向每个文件发送和接受元数据。
前端:Angularjs
后端:Groovy/Java、Spring 3.0
@RequestMapping(value = "/view/single/multi-file", method = POST, produces = APPLICATION_JSON_VALUE)
def createNewAdjustment(@RequestParam("files") List<List<MultipartFile>> files,
@RequestParam("data") List<DataRequest> data){}
所以在上面的代码中:
- the list of lists: are the files that needs to be processed and saved.
- the data: is the list of objects that needs to be processed,saved and interconnect them with files.
请求负载如下所示:
------WebKitFormBoundaryPve8x58T1pAIsQOS
Content-Disposition: form-data; name="data"
{"rollNumber":"1111111111111","compId":213131,"adjId":"260b018c-5921-4c1c-aa99-ba8587ee4777"}
------WebKitFormBoundaryPve8x58T1pAIsQOS
Content-Disposition: form-data; name="files"; filename="some.json.gz"
Content-Type: application/x-gzip
------WebKitFormBoundaryPve8x58T1pAIsQOS
Content-Disposition: form-data; name="files"; filename="someother.csv.gz"
Content-Type: application/x-gzip
------WebKitFormBoundaryPve8x58T1pAIsQOS--
您可以看到 'name: "file"' 重复了 2 次,我不确定如何手动设置或/以及将更多内容附加到请求中。有什么想法吗?
【问题讨论】:
标签: angularjs spring http file-upload groovy