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);
        }
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章