EAS WEB附件下载实现

方式一:请求后台代码方式

        //前端js:

	    //调用后台,封装附件数据
          waf.doPost({
   
                action:"AttachmentListUIService",
                data:{
   
                    methodName: "getFiles",
                    ids: ids //附件id数组
                },
                success:function(result){
   
                    for(var j=0;j<result.length;j++){
   
                        var dataMap = result[j];
                        //文件字节流
                        var fileByte = dataMap.fileByte;
                        //字节流数组转换
                        var arr = new Uint8Array(fileByte.length);
                        for (var i = 0;i<fileByte.length;i++){
   
                             arr[i] = fileByte[i];
                        }
                        //文件名
                        var fileName = dataMap.fileName;
                        var url = window.URL.createObjectURL(new Blob([arr]));
                        var link = document.createElement('a');
                        link.style.display = 'none';
                        link.href = url;
                        link.setAttribute('download', fileName);
                        document.body.appendChild(link);
                        link.click();
                        document.body.removeChild(link);
                   }
                }
            });
	   //后台代码:

        private HashSet getFilesObj(KDActionEvent event) throws EASBizException, BOSException {
   
        HashSet dataSet = new HashSet();
        //所选id封装
        String[] ids = (String[])event.getReqeustContext().getHttpServletRequest().getParameterMap().get("ids[]");
        HashSet<String> idSet = new HashSet<String>(Arrays.asList(ids));
        //查询所选id附件
        EntityViewInfo view = new EntityViewInfo();
        FilterInfo filterInfo = new FilterInfo();
        filterInfo.getFilterItems().add(new FilterItemInfo("id",idSet,CompareType.INCLUDE));
        view.setFilter(filterInfo);
        AttachmentCollection coll = AttachmentFactory.getRemoteInstance().getAttachmentCollection(view);
        //遍历附件集合
        for(int i=0;i<coll.size();i++){
   
            //存储当前文件信息
            HashMap<String,Object> dataMap = new HashMap<String,Object>();
            AttachmentInfo attachmentInfo = coll.get(i);
            attachmentInfo = AttachmentFactory.getRemoteInstance().getAttachmentInfo(new ObjectUuidPK(attachmentInfo.getId()));
            //文件名称
            String fileName = attachmentInfo.getName();
            //文件类型
            String simpleName = attachmentInfo.getSimpleName();
            //文件数据
            byte[] fileBtye = null;
            //文件存储方式
            AttachmentStorageTypeEnum storageType = attachmentInfo.getStorageType();
            if(storageType.equals(AttachmentStorageTypeEnum.FTP)){
   
                //ftp服务器方式
                FtpConfigInfo ftp = attachmentInfo.getFtp();
                ftp = FtpConfigFactory.getRemoteInstance().getFtpConfigInfo(new ObjectUuidPK(ftp.getId()));
                String remotePath = attachmentInfo.getRemotePath();
                byte[] file = FtpHandleFacadeFactory.getRemoteInstance().download(ftp, remotePath);
            }else if(storageType.equals(AttachmentStorageTypeEnum.DATABASE)){
   
                //数据库方式
                fileBtye = attachmentInfo.getFile();
            }
            //封装数据
            dataMap.put("fileName", fileName+"."+simpleName);
            dataMap.put("fileByte", fileBtye);
            dataSet.add(dataMap);
        }
        return dataSet;
    }

方式二:标准web链接下载方式

        downloadFiles: function (e) {
   
            //附件id
            var ids = waf("#queryGrid").wafGrid("getSelectedRows");
            if (ids == null || ids == "") {
   
                _self.showWarning("请选择需要下载的附件。");
                return false;
            }
            //批量下载
            for (var i = 0; i < ids.length; i++) {
   
                //文件名
                var fileName = waf("#queryGrid").wafGrid("getCell", ids[i], "name");
                var fileType = waf("#queryGrid").wafGrid("getCell", ids[i], "simpleName");
                var link = document.createElement('a');
                link.style.display = 'none';
                link.href = "/easweb/webviews/webframework/webcom/attachment/download.jsp?bosID=" + ids[i];
                link.setAttribute('data_url', ids[i]);
                link.setAttribute('target', "_blank");
                link.setAttribute('download', fileName + "." + fileType);
                document.body.appendChild(link);
                link.click();
                document.body.removeChild(link);
            }
        }

相关推荐

  1. EAS WEB附件下载实现

    2024-01-06 21:22:01       36 阅读
  2. js直接下载附件和通过blob数据类型下载文件

    2024-01-06 21:22:01       37 阅读
  3. 实现文件下载

    2024-01-06 21:22:01       19 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-06 21:22:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-06 21:22:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-06 21:22:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-06 21:22:01       20 阅读

热门阅读

  1. 基于SpringBoot的物流管理系统

    2024-01-06 21:22:01       43 阅读
  2. 高考组数。

    2024-01-06 21:22:01       45 阅读
  3. MySQL5.7无法连接到[本地] MySQL 服务器

    2024-01-06 21:22:01       47 阅读
  4. 新版Edge如何卸载详细讲解

    2024-01-06 21:22:01       50 阅读
  5. 新版EDGE卸载

    2024-01-06 21:22:01       38 阅读
  6. c++求一个数是否是质数

    2024-01-06 21:22:01       42 阅读
  7. vue 微信扫码登录

    2024-01-06 21:22:01       48 阅读
  8. spring 之 TransactionManager使用详解

    2024-01-06 21:22:01       39 阅读
  9. python&Matplotlib四:Matplotlib设置图的样式和颜色

    2024-01-06 21:22:01       34 阅读
  10. 【Vue】灵魂拷问

    2024-01-06 21:22:01       34 阅读
  11. Flutter中的NotificationCenter和EventBus(超级简单!)

    2024-01-06 21:22:01       46 阅读
  12. Rabbitmq下载安装图文详解(Windows版_超详细)

    2024-01-06 21:22:01       41 阅读