@GetMapping("/downloadImage")
public void downloadImage(HttpServletResponse response) throws IOException {
String url = "group1/M00/30/FE/ChOXjl-915aAavo4AAR0lsBNT2c417.jpg";
OutputStream out = null;
try {
//获取图片字节流
byte[] bytes = fastDFSClientWrapper.downloadFile(url);
//设置文件名
String fileName = "图片.jpg";
String fileNameURL = URLEncoder.encode(fileName, "UTF-8");
//设置接口的Header
response.setContentType("application/octet-stream;charset=ISO8859-1");
response.setHeader("Content-Disposition", "attachment;filename=" + fileNameURL + ";" + "filename*=utf-8''" + fileNameURL);
response.setHeader("filename", fileNameURL);
response.setHeader("Access-Control-Expose-Headers", "filename");
response.setHeader("Access-Control-Allow-Origin", "*");
//字节流写出到客户端
out=response.getOutputStream();
out.write(bytes);
} catch (Exception e) {
e.printStackTrace();
}finally {
out.close();
}
}
图片字节流写出到客户端,实现图片下载
最新推荐文章于 2022-02-17 15:10:19 发布