/** * 线预览图片查看 * * @param response */ public void doDowloadImgFile(HttpServletResponse response, String tsUrl) { OutputStream os = null; try { os = response.getOutputStream(); Assert.notNull(tssUrl, "加载图片路径为空"); response.setContentType("image/jpeg"); InputStream in = tsUtil.downloadUrl(tssUrl); parse(in, os); response.flushBuffer(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(os); } } public void parse(InputStream in, OutputStream out) throws Exception { int ch; while ((ch = in.read()) != -1) { out.write(ch); } }
服务器在线图片预览
最新推荐文章于 2025-04-26 10:48:04 发布
本文介绍了一个用于在线预览并下载图片的方法。通过使用Java Servlets,该方法能够接收图片URL,将其加载到内存中,并以JPEG格式返回给客户端进行预览。此过程包括从远程URL下载图片、读取图片内容并将其发送到用户的浏览器。
805

被折叠的 条评论
为什么被折叠?



