码迷,mamicode.com
首页 > 其他好文 > 详细

从七牛服务下载PDF文件

时间:2016-03-14 12:17:22      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

/**
     * 从七牛下载PDF文件
     * @param request
     * @param response
     * @param exhiId
     * @throws MalformedURLException
     */
    @RequestMapping("/loadCanZhanHan")
    public void downloadNet(HttpServletRequest request, HttpServletResponse response,String exhiId) throws MalformedURLException{
        ExhiMain exhiMain = exhiMainService.get(exhiId);
        String canZhanHanUrl = exhiMain.getCanZhanHanUrl();
        try {
            if(canZhanHanUrl !=null && !"".equals(canZhanHanUrl)){
                PDFUtil.downloadZhaoZhanHan(response, canZhanHanUrl);
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        
       }
/**
      * 下载七牛上面的PDF文件
      * @param response 
      * @param canZhanHanUrl 七牛上的文件地址
      * @throws Exception
      */
    public static void downloadZhaoZhanHan(HttpServletResponse response,String canZhanHanUrl) throws Exception{
        int byteread=0;
        URL url = new URL(canZhanHanUrl);
        try {
            URLConnection conn = url.openConnection();
            InputStream inStream = conn.getInputStream();
            ServletOutputStream outputStream = response.getOutputStream();
            
            response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode("招展函.pdf", "UTF-8"));
            response.setContentType("application/force-download");
             byte[] buffer = new byte[1024];
             while((byteread=inStream.read(buffer)) !=-1) {
                 outputStream.write(buffer, 0, byteread);
             }
        } catch (Exception e) {
            e.printStackTrace();
        }
        
    }

 

从七牛服务下载PDF文件

标签:

原文地址:http://www.cnblogs.com/SHMILYHP/p/5275161.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!