zoukankan      html  css  js  c++  java
  • 从七牛服务下载PDF文件

    /**
         * 从七牛下载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();
            }
            
        }

     js:

    var e = $('input[name="exhiId"]').val();
                        window.location.href = pageConfig.ctx + "/exhi/loadCanZhanHan?exhiId=" + e
  • 相关阅读:
    MySQL表之间的关系概述
    网路通信简介
    多态与鸭子类型
    组合与类继承
    类与对象的属性与方法以及封装
    对象与类的初始
    2018.12.12
    2018.12.9浮动布局,盒子显隐,定位,z-index,流式布局,小米开头
    2018.12.8浮动布局,display总结,overflow,清浮动
    2018.12.7边界圆角redius,背景图设置,平铺,精灵图,盒子伪类索引
  • 原文地址:https://www.cnblogs.com/SHMILYHP/p/5275161.html
Copyright © 2011-2022 走看看