Spring Boot Angular 8多文件zip下载
我正在下载带有spring boot和angular的多文件zip。它与spring boot postman一起工作,但当我执行angular执行时,它会下载这样的文件 弹簧靴Spring Boot Angular 8多文件zip下载,angular,spring-boot,file,zip,zipfile,Angular,Spring Boot,File,Zip,Zipfile,我正在下载带有spring boot和angular的多文件zip。它与spring boot postman一起工作,但当我执行angular执行时,它会下载这样的文件 弹簧靴 @GetMapping("/fileZIP/{personId}") public void getAllFile(@PathVariable(value = "personId") Integer personId, HttpServletResponse respo
@GetMapping("/fileZIP/{personId}")
public void getAllFile(@PathVariable(value = "personId") Integer personId, HttpServletResponse response) throws FileNotFoundException, IOException {
List<File> fileList = service.findByFile(personId);
String zipName = person.getName() + "_" + person.Surname() + ".zip";
FileOutputStream fileOutputStream = new FileOutputStream(zipName);
ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(fileOutputStream));
for (File file : fileList) {
FileSystemResource resource = new FileSystemResource(file.getFilePath());
ZipEntry zipEntry = new ZipEntry(resource.getFilename());
zipEntry.setSize(resource.contentLength());
zipOut.putNextEntry(zipEntry);
StreamUtils.copy(resource.getInputStream(), zipOut);
zipOut.closeEntry();
}
zipOut.finish();
zipOut.close();
response.setContentType("application/octet-stream");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", String.format(" attachment; filename=\"%s\"", zipName));
}
角度服务
getFilePerson(personId: number,headers): Observable<any> {
return this.http.get(apiHost + '/fileZIP/' + personId,{ headers, responseType: 'arraybuffer' }).pipe(
map((data: any) => {
return data;
})
);
}
getFilePerson(personId:number,headers):可观察{
返回这个.http.get(apiHost+'/fileZIP/'+personId,{headers,responseType:'arraybuffer'}).pipe(
地图(数据:任意)=>{
返回数据;
})
);
}
getFilePerson(personId: number,headers): Observable<any> {
return this.http.get(apiHost + '/fileZIP/' + personId,{ headers, responseType: 'arraybuffer' }).pipe(
map((data: any) => {
return data;
})
);
}