从服务器文件系统中的文件加载pdf浏览器?

从服务器文件系统中的文件加载pdf浏览器?,第1张

从服务器文件系统中的文件加载pdf浏览器?

更改

res.setHeader("Content-Disposition", "attachment;filename=report.pdf");

res.setHeader("Content-Disposition", "inline;filename=report.pdf");

您还应该设置内容长度

FileCopyUtils很方便:

@Controllerpublic class FileController {    @RequestMapping("/report")    void getFile(HttpServletResponse response) throws IOException {        String fileName = "report.pdf";        String path = "/path/to/" + fileName;        File file = new File(path);        FileInputStream inputStream = new FileInputStream(file);        response.setContentType("application/pdf");        response.setContentLength((int) file.length());        response.setHeader("Content-Disposition", "inline;filename="" + fileName + """);        FileCopyUtils.copy(inputStream, response.getOutputStream());    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5639342.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存