本文主要是介绍Java调用接口获得图片输入流InputStream并返回给前端,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
效果:
代码:
export const getPhotoById = params => get(`${base}/weda/myLecture/poster/template/getPhotoById?id=${params.id}&isPreview=${params.isPreview}`,{}); // 获取原始的大图
后端
@Overridepublic void getPhotoById(PosterTemplate dto, HttpServletResponse response) throws Exception {/省略InputStream download = minioUtil.download("mpbucket", "sjs/wdjz/hbgl" + SLASH_SUFFIX + preview);writeFile(response,download);}/*** 将输入流输出到页面*/public static void writeFile(HttpServletResponse resp, InputStream inputStream) {OutputStream out = null;try {out = resp.getOutputStream();int len = 0;byte[] b = new byte[1024];while ((len = inputStream.read(b)) != -1) {out.write(b, 0, len);}out.flush();} catch (IOException e) {e.printStackTrace();} finally {try {if (out != null) {out.close();}} catch (Exception e) {e.printStackTrace();}}}
这篇关于Java调用接口获得图片输入流InputStream并返回给前端的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!