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

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"));
		}
	}



你可能感兴趣的:(exception,String,upload,File,null,Path)