我的目标是将一个zip文件上传到我的Angular 2前端,并将其发送到我的Java(Spring Boot)后端并处理zip中包含的xml文件。
我正在使用JSZip将zip文件上传到我的Angular 2应用程序(但随意提出其他解决方案)。
问题是我不知道如何从前端发送zip文件,以及如何在后端接收它。
目前,我正在发送JSZip对象,如下所示:
{
"files":{
"file1.xml":{
"name":"file1.xml",
"dir":false,
"date":"2017-05-17T11:43:24.000Z",
"comment":null,
"unixPermissions":33188,
"dosPermissions":null,
"_data":{
"compressedSize":1408,
"uncompressedSize":7120,
"crc32":-1714370258,
"compression":{
"magic":"\b\u0000"
},
"compressedContent":{
"0":165,
"1":89,
"2":93,
"3":147,
(...)
"1348":54
}
},
"_dataBinary":true,
"options":{
"compression":null,
"compressionOptions":null
}
},
"file2.xml":{
(...)
}
},
"comment":null,
"root":""
}如何在Java中处理这些数据,以及如何处理xml文件?
基于this GitHub issue,
我试过这个:
@PostMapping(path = "zip")
public void importZip(@RequestBody final byte [] zipBytes) throws IOException {
final ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(zipBytes));
zipStream.getNextEntry();
ZipEntry entry;
while ((entry = zipStream.getNextEntry()) != null) {
System.out.println(entry.getName());
}
}但entry始终为null,并且不显示任何内容。
我该怎么做?
非常感谢。