设置Content-Disposition=attachment和filename=xyz.zip使用Spring 3 的最合适,最标准的方法是FileSystemResource什么?
该动作如下:
@ResponseBody
@RequestMapping(value = "/action/{abcd}/{efgh}", method = RequestMethod.GET, produces = "application/zip")
@PreAuthorize("@authorizationService.authorizeMethod()")
public FileSystemResource doAction(@PathVariable String abcd, @PathVariable String efgh) {
File zipFile = service.getFile(abcd, efgh);
return new FileSystemResource(zipFile);
}
Run Code Online (Sandbox Code Playgroud)
虽然该文件是一个zip文件,因此浏览器总是下载该文件,但我想明确提到该文件为附件,并提供与文件实际名称无关的文件名.
可能有解决此问题的方法,但我想知道正确的Spring和FileSystemResource实现此目标的方法.
PS此处使用的文件是临时文件,在JVM存在时标记为删除.