EAS BOS上传附件及后台下载附件

本文介绍了一种在特定业务环境中实现文件操作的方法,包括获取业务对象ID、上传和下载附件的功能实现。通过与远程服务交互完成附件的上传及下载流程,并针对下载过程中可能出现的数据压缩情况做了特别处理。
protected final String getSelectBOID() throws EASBizException, BOSException {
		PRT_AGENTInfo ptInfo = getAgentInfo();
		if (ptInfo == null) {
			return null;
		} else {
			String boID = ptInfo.getId() == null ? null : ptInfo.getId()
					.toString();
			return boID;
		}
	}

/**
*上传附件
*/
public void upload(){
                AttachmentClientManager acm = AttachmentManagerFactory
				.getClientManager();
		boolean isEdit = false;
		int rowIndex = CNTT.getSelectManager().getActiveRowIndex();
		if (rowIndex != -1)
			isEdit = true;
		AttachmentUIContextInfo info = getAttacheInfo();
		if (info == null)
			info = new AttachmentUIContextInfo();
		if (info.getBoID() == null || info.getBoID().trim().equals("")) {
			String boID = getSelectBOID();
			if (boID == null)
				return;
			info.setBoID(boID);
		}
		info.setEdit(isEdit);
		String multi = (String) getUIContext().get("MultiapproveAttachment");
		if (multi != null && multi.equals("true"))
			acm.showAttachmentListUIByBoIDNoAlready(this, info);
		else
			acm.showAttachmentListUIByBoID(this, info);
}
下载附件
/**
*attchID 附件ID
*path 下载后存放的路径
*/
private void downloadAttachment(String attchID, String path)
			throws EASBizException, BOSException {
		ia = (IAttachment) AttachmentFactory.getRemoteInstance();
		AttachmentInfo ai;
		SelectorItemCollection sic = new SelectorItemCollection();
		sic.add(new SelectorItemInfo("name"));
		sic.add(new SelectorItemInfo("simpleName"));
		sic.add(new SelectorItemInfo("sizeInByte"));
		ai = (AttachmentInfo) ia.getValue(new ObjectUuidPK(attchID), sic);
		String waitAttachmentId = ai.getId().toString();
		ByteArrayOutputStream dataByte = new ByteArrayOutputStream();
		java.io.OutputStream out = dataByte;
		AttachmentDownloadClient downloadClient = new AttachmentDownloadClient(
				AttachmentFtpFacadeFactory.getRemoteInstance());
		downloadClient.setOutputStream(out);
		downloadClient.downLoad(waitAttachmentId);
		ai.setFile(dataByte.toByteArray());
		logger.info(ai.getName());
		try {
			FileOutputStream fos = new FileOutputStream(path);

			if (ai.getFile().length == ai.getSizeInByte()) {
				logger.info("....... no unpack ");
				fos.write(ai.getFile());
			} else {
				logger.info("....... unpack , file length is:"
						+ ai.getFile().length + " oldSize is:"
						+ ai.getSizeInByte());
				fos.write(DataZipUtils.UnDataZip(ai.getFile()));
			}
			fos.close();
		} catch (Exception e) {
			MsgBox.showInfo(Resrcs.getString("PathNotExisted"));
		}
	}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值