这是我的代码,位于代码下方。
@GetMapping(value = "/download/tutorial/{tutorialId}", produces = "application/zip")
public void zipDownload(@PathVariable String tutorialId, HttpServletResponse response) throws IOException {
ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream());
List<TutorialFileDownload> downloads = tutorialFileService.downloadFiles(compos.getLong(tutorialId));
for (TutorialFileDownload f : downloads) {
FileSystemResource resource = new FileSystemResource(dropBoxService.downloadFile(f.getFilename(), f.getPathLower()));
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.setStatus(HttpServletResponse.SC_OK);
response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=test.zip");
}
这是响应