博主首页

html页面直接回显接口返回的图片文件流

   <img src="http://127.0.0.1:8081/t1/img">
    @GetMapping("/img")
    @SneakyThrows
    public void test01(HttpServletResponse response){
        String jp = Jie截屏.jp(0, 0, 300, 200, "D:\\桌面文档\\123.png");
        File ossObjectToFile = new File(jp);
        try(ServletOutputStream outputStream = response.getOutputStream();
                FileInputStream fileInputStream = new FileInputStream(ossObjectToFile)){
                response.addHeader("Content-Disposition", "attachment;filename=123.png");
                response.setContentType("application/octet-stream");
                IOUtils.copy(fileInputStream,outputStream);
        }
    }

 

posted @ 2024-02-19 14:25  笑~笑  阅读(112)  评论(0编辑  收藏  举报