How to set 'Content-Disposition' and 'Filename' when using FileSystemResource to force a file download file?

后端 未结 5 631
囚心锁ツ
囚心锁ツ 2020-12-13 17:52

What is the most appropriate, and standard, way to set the Content-Disposition=attachment and filename=xyz.zip using Spring 3 FileSystemResou

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 18:16

     @RequestMapping(value = "/files/{file_name}", method = RequestMethod.GET)
        @ResponseBody
        public FileSystemResource getFile(@PathVariable("file_name") String fileName,HttpServletResponse response) {
            response.setContentType("application/pdf");      
            response.setHeader("Content-Disposition", "attachment; filename=somefile.pdf"); 
            return new FileSystemResource(new File("file full path")); 
        }
    

提交回复
热议问题