Attachment provider to store files in disk

I need to create a custom attachment provider to keep attachments in a disk file instead of using the folders inside mwm.

I cannot find how to implement it. I created a provider extending com.webMethods.caf.faces.data.attachments.TempAttachmentsProvider but I cannot make it work with other stuff other than the folders inside the MWM server.

I need also to be able to create subfolders dynamically (the same way that createTempFolder() does).

Thanks
Edgardo

Please see the attached example.
There is a function that iterates through the temp attachment provider and writes the files to disk (on a per user basis) inside the MWS temp directory. I imagine that you’ll want to write to different directories, so you should be able to alter as needed, but the sample does demonstrate creating directories as well:

	public void uploadDocs() throws Exception {
		String dirPath = PathUtil.appendPath(FileUtil.getTempDirectory(), getFacesContext().getExternalContext().getRemoteUser());
		File dir = new File(dirPath); 
		dir.mkdir(); 

		//loop through attachments and write them to the filesystem 
		List<IAttachmentItem> files = getTemporaryAttachmentsProvider().listAttachments(); 
		for (IAttachmentItem file: files){ 
			String path = PathUtil.appendPath(dir.toString(), file.getFileName());
			File f = new File(path); 
			try { 
				log("writing: " + file.getFileItem().getName()); 
				FileOutputStream fos = new FileOutputStream(f); 
				InputStream fis = file.getFileItem().getInputStream(); 
				FileUtil.copyStream(fis, fos); 
			} catch (Exception e) { 
				log(e);
			}
		} 
	}

Regards,
–mark
AttachmentApp.zip (9.02 KB)

thanks mark:

The load part works right, I’m working through the listAttachment() method now and it works right but I can some problem with displaying the icons corresponding to each file in the attachment panel.

Edgardo

You’re welcome. Did you have a follow-up question?

Are these temp directories available in through the browser, or only on the server?

the temp directory isn’t (and probably shouldn’t) be exposed directly through the servlet engine via directory browsing.

I didn’t think so. Humm…

I’m trying to figure out if there is a way to move a file to the MWS server, expose it, and still have access control such that only the creator can see it. I’ve tried the attachement appraach but it’s too clever for my needs.

Streaming it works great (see: My Other Thread) but I’m afraid with large PDFs the Data URI limitations will come into play …or maybe I’m misunderstanding them.

Data URI Wikiedia Article

Thanks boss,

Lucas.

Mark,
I’m trying to import the sample project into 7.1.3 designer and it throws a invocation target exception.

Please let me know if this project is delveoped in 8.2 designer.

Thanks,
Sravan

Sravan, yes that is developed for 8.2 designer. However, it doesn’t use 8.2 specific features so i think you should be able to examine the .java and the .view file to replicate this in 7.x Designer.

Regards,
–mark

Hi Experts,

Very helpful discussion indeed. But from the below Attachment provider implementation, only icon is getting displayed without any hyperlink or download popup(Or even save link as option). So how can i modify so that, if the user directly left clicks on attachment it should prompt Save as popup and if he right clicks on it, it should give Save as option to copy the file in local system.

Regards,
Niteesh