在線預覽附件圖片

/**
     * 在線預覽圖片
     * @param path 上傳路徑
     * @param response
     */
    @RequestMapping(value ="/showImage/{path}",method = RequestMethod.GET)
    @ResponseBody
    public void showImage(@PathVariable String path,HttpServletResponse response) throws IOException {
        response.setContentType("text/html; charset=UTF-8");
        response.setContentType("image/jpeg");
        String fullFileName = "C:/upload/" + path;        
        FileInputStream fis = new FileInputStream(fullFileName);
        OutputStream os = response.getOutputStream();
        try {
            int count = 0;
            byte[] buffer = new byte[1024 * 1024];
            while ((count = fis.read(buffer)) != -1)
                os.write(buffer, 0, count);
            os.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (os != null)
                os.close();
            if (fis != null)
                fis.close();
        }
    }

 

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