img

以流的方式

 	/**
 * 获取主接线图流
 * @param uri 相对路径(ftp返的路径)
 */
@GetMapping("/img")
@ResponseBody
public void getImg(@RequestParam String uri, HttpServletResponse res) throws IOException {
	if (StringUtil.isBlank(uri)) {
		// 非上传窗口请求
		return;
	}
	InputStream in = uploadFileService.downloadFile(uri);
	BufferedImage buffImg = ImageIO.read(in);
	String imgType = uri.substring(uri.lastIndexOf(".") + 1);
	res.setContentType("image/"+ imgType);
	ServletOutputStream os = res.getOutputStream();
	ImageIO.write(buffImg, imgType, os);
	os.flush();
	os.close();
	in.close();
}
posted @ 2022-06-06 11:10  jf666new  阅读(77)  评论(0)    收藏  举报