我正在尝试从springboot控制器下载一个zip文件,但是却收到了奇怪的响应。请协助

时间:2019-12-18 16:07:17

标签: java

这是我的代码,位于代码下方。

@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");
    }

这是响应

Response

0 个答案:

没有答案