小编Has*_*mil的帖子

使用FileSystemResource强制文件下载文件时如何设置'Content-Disposition'和'Filename'?

设置Content-Disposition=attachmentfilename=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存在时标记为删除.

java spring content-disposition spring-3

27
推荐指数
4
解决办法
5万
查看次数

标签 统计

content-disposition ×1

java ×1

spring ×1

spring-3 ×1