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
  • 相关阅读:
    用迭代法求x=a−−√。求平方根的迭代公式为 xn+1 = 12(xn + axn) 要求前后两次求出的x的差的绝对值小于10−5
    C 数组
    fofa自动化爬虫脚本更新+详解
    c# winfrom接收http协议body数据
    FLW要求
    modbus工具问题
    2020年总结
    WIFI K型热电偶传感器
    泛海三江烟感JTY-GD-H361 V2.7
    工位终端
  • 原文地址:https://www.cnblogs.com/SHMILYHP/p/5275161.html
Copyright © 2011-2022 走看看