java - 我正在尝试从 springboot 控制器下载一个 zip 文件,但我得到了奇怪的响应。请协助
问题描述
这是我的代码和代码下方的响应。
@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");
}
这是回应
解决方案
推荐阅读
- c++ - 两个堆分配是否比调用 std::string 填充 ctor 更昂贵?
- python - Phemex CCXT Python 为订单添加止损和获利
- python - ValueError:Layer Discriminator 需要 1 个输入,但它接收到 2 个输入张量
- c++ - c++ makefile找不到目录
- c++ - 如何区分C++中的两个派生类
- r - R:将列拆分为两列
- javascript - Javascript - 如何获取触发事件的元素
- database - 如何使用无状态服务跟踪随机数
- jquery - jQuery 返回 $.getJSON 值
- arrays - 用于迭代选择矩阵列的 Octave 或 Matlab 代码