【发布时间】:2015-12-15 10:24:22
【问题描述】:
我遇到了范围问题。我正在尝试拥有一个允许用于下载 zip 文件的 Spring 控制器。这是有效的 sn-p,当用户向 url 发出 get 请求时,浏览器开始文件下载
@RequestMapping(value = "mypath/",method = RequestMethod.GET)
public void downloadFiles(@PathVariable("id") String id) {
InputStream a = new ByteArrayInputStream(fileService.get(id));
StringBuilder sb = new StringBuilder("attachment; filename=).append(id).append(".zip");
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, sb.toString());
org.apache.commons.io.IOUtils.copy(a, response.getOutputStream());
response.setContentType("application/x-download");
response.flushBuffer();
}
但是...如果我将 IOUtils.copy 替换为 FileCopyUtils.copy,当我点击 url 时,浏览器只会显示文件的内容而不是下载它
可以解释一下发生了什么吗?
【问题讨论】:
标签: java spring download copy zip