直接从本地拿取图片给前端显示,直接给前端流数据:
public static void getPhoto(HttpServletResponse response, String imgUrl) throws Exception {
String path = "你的路径" + imgUrl;
File file = new File(path);
FileInputStream fis;
fis = new FileInputStream(file);
long size = file.length();
byte[] temp = new byte[(int) size];
fis.read(temp, 0, (int) size);
fis.close();
byte[] data = temp;
response.setContentType("image/png");
OutputStream out = response.getOutputStream();
out.write(data);
out.flush();
out.close();
}