(507条消息) Springboot实现上传文件以及文件实时预览(包括图片预览,视频预览)_springboot 图片预览_柯小帅的博客-CSDN博客
@GetMapping("preview")
@ApiOperation(value = "根据文件名实现预览功能")
public void previewFile(
HttpServletResponse response) throws IOException {
showImg("D:\\"+"p28869923647.png", response);
}
public static void showImg(String path, HttpServletResponse response){
if(path!=null&&!path.equals("")){
try {
FileInputStream fis = new FileInputStream(path);
ServletOutputStream os = response.getOutputStream();
byte [] b = new byte[1024*8];
while(fis.read(b)!=-1){
os.write(b);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}