标签:stream public cep 下载 body filename false UI get
一、不在同一台主机,通过给对方文件的方式Controller
@RequestMapping(value = "/down/{uuid}", method = RequestMethod.GET) @ResponseBody public void downloadImage(@PathVariable("uuid") final String uuid, HttpServletResponse response) { flService.downImage(uuid, response); }
service
void downImage(String uuid, HttpServletResponse response);
serviceImpl
@Override public void downImage(String uuid, HttpServletResponse response) { //response.setHeader("Content-Disposition", "attachment;fileName=" + "asdf.jpg"); //下载 response.setContentType("image/png");//显示 String realPath = "C:\\Users\\Public\\Pictures\\Sample Pictures\\asdf.jpg"; InputStream fileInputStream; try { fileInputStream = new FileInputStream(realPath ); OutputStream outputStream = response.getOutputStream(); IOUtils.copy(fileInputStream, outputStream); outputStream.close(); fileInputStream.close(); } catch (Exception e) { e.printStackTrace(); } }
实现文件下载
response.setHeader("Content-Disposition", "attachment;fileName=" + "asdf.jpg");
实现文件在浏览器显示
response.setContentType("image/png");
二、如果在同一台主机,可以将url给对方,通过nginx代理的方式访问。
标签:stream public cep 下载 body filename false UI get
原文地址:http://blog.51cto.com/1385903/2067365