cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Uploaded file?

Amethyst

How to get Uploaded file?

I have created a wizard using attachments tags.

 

<attachments:fileSelectionAndUploadApplet/>

<attachmentsSmiley TonguerimaryAttachment>

 

I am able to display browser option on wizard.

How to get that file on form Processor?

1 REPLY 1
Highlighted

Re: How to get Uploaded file?

Did you ever solve this problem? If so, could please share the code?

I figured it out, but it's a little bit tricky and I'm not sure if I did it the right way, but it works.

This method is not finished, it's just an example to add an uploaded file as a primary of a WTDocument. If already a primary exists it need to be deleted first. So it will only work for a WTDocument with no file attached.

 

@Override
public FormResult doOperation(NmCommandBean nmCommandBean, List<ObjectBean> list) throws WTException {
	FormResult formResult = new FormResult();
	ObjectIdentifier oidObject = nmCommandBean.getElementOid().getOidObject();
	WTDocument wtDocument = (WTDocument) PersistenceHelper.manager.refresh(oidObject);
	try {

		ContentHolder contentHolder = ContentHelper.service.getContents(wtDocument);

		for (ObjectBean bean : list) {
			log.debug("bean = \"{}\"", bean.getParameterMap());
			Map<String, String> text = bean.getText();
			String oid = null;
			String filename = null;
			String cachedContentDescriptorValue = null;
			for (Map.Entry<String, String> entry : text.entrySet()) {
				String key = entry.getKey();
				log.debug("key = \"{}\"", key);
				if (key.startsWith("PRIMARY_FILE") && key.endsWith("_cachedContentDescriptor")) {
					oid = key.replace("PRIMARY_FILE_", "").replace("_cachedContentDescriptor", "");
					log.debug("oid = \"{}\"", oid);
					cachedContentDescriptorValue = entry.getValue();
					log.debug("cachedContentDescriptorValue = \"{}\"", cachedContentDescriptorValue);
				} else if (key.startsWith("PRIMARY_FILE") && key.endsWith("_filePath" )) {
					filename = entry.getValue();
				}
			}
			if (filename != null && oid != null && cachedContentDescriptorValue != null) {
				ApplicationData applicationData = ApplicationData.newApplicationData((ContentHolder) null);
				applicationData.setFileName(filename);
				CachedContentDescriptor cachedContentDescriptor = new CachedContentDescriptor(cachedContentDescriptorValue);
				applicationData.setRole(ContentRoleType.PRIMARY);
				applicationData.setContentIdentity(cachedContentDescriptor.getContentIdentity());
				ContentServerHelper.service.updateContent(contentHolder,applicationData,cachedContentDescriptor);
			}

		}
	} catch (PropertyVetoException e) {
		log.error("Error 155122:", e);
	}


	return formResult;
}