filenet-p8filenetfilenet-process-engine

How to get the Name, MIME Type and Content of a VWAttachment in Filenet P8?


I have been trying to get the name, MIME type and content of a VWAttachment in FileNet P8. The content should be a byte array or an input stream.

UPDATE:

String name = attachment.getAttachmentName();

Gives me the name of VWAttachment. And let's say by looking at the file extension I can decide proper MIME type. I need to know how can I get the content of the attachment in an InputStream

Any help is appreciated. Thanks!


Solution

  • You need to use the information in the VWAttachment object to fetch the correct document from the Content Engine.

    for example:

    com.filenet.api.core.Domain domain = (...you need to get this);
    VWAttachment vwAttachment = (...you already have this);
    
    ObjectStore objectStore = Factory.ObjectStore.getInstance(domain, vwAttachment.getLibraryName());
    VersionSeries vs = Factory.VersionSeries.fetchInstance(objectStore, new Id( vwAttachment.getId()), null);
    Document document = (Document) vs.get_CurrentVersion();
    
    ContentTransfer contentTransfer = (ContentTransfer) document.get_ContentElements().get(0);
    InputStream inputStream = contentTransfer.accessContentStream();