/** * 预览-public * * @param response * @param fileName * @param fileCode */ @RequestMapping("/previewPublic") public void previewPublic(HttpServletResponse response, String fileName, String fileCode) throws IOException { //每个项目中需要的路径不太一样,需要根据实际需求指定文件的路径 String filePath = uploadPath + "/" + BUCKET_NAME + "/" + fileCode; try { File file = new File(filePath); FileInputStream fileInputStream = new FileInputStream(file); if (fileName.endsWith("pdf")) { response.setHeader("Content-Type", "application/pdf"); } OutputStream outputStream = response.getOutputStream(); IOUtils.write(IOUtils.toByteArray(fileInputStream), outputStream); } catch (Exception e) { e.printStackTrace(); } }
文件预览,只针对PDF,简单有效
最新推荐文章于 2024-08-26 23:25:51 发布