当我尝试下载zip文件时,它下载成功,但下载的文件名为"download.zip",与@GetMapping Annotation的value参数相匹配。
@GetMapping(value = "/download", produces = "application/zip")
public @ResponseBody byte[] getFile() throws IOException {
InputStream inputStream = new FileInputStream(downloadDir + "check.zip");
return IOUtils.toByteArray(inputStream);
}如何设置下载文件的具体名称?提前感谢您的回复!
发布于 2020-04-22 23:05:57
您应该将其作为响应头返回:content-disposition : "attachment; filename=check.zip"
-->
@GetMapping(value = "/download", produces = "application/zip")
public @ResponseBody byte[] getFile(HttpServletResponse response) throws IOException {
InputStream inputStream = new FileInputStream(downloadDir + "check.zip");
response.setHeader("Content-Disposition", "attachment; filename=check.zip");
return IOUtils.toByteArray(inputStream);
}https://stackoverflow.com/questions/61368195
复制相似问题