How to Store attachment into hard drive .

1
0
-1

how can i store attachment(document) from process uploaded by user to harddrive . it can be any type of document , .pdf , .doc , .xls etc.

Pl help . give any example .

1 answer

1
0
-1

Hello,

Assuming that a document is declared with the name "myDocument" in your process definition:

  1. String attachment = "myDocument";
  2. org.bonitasoft.engine.bpm.document.Document srcDocument =
  3. processAPI.getLastDocument(processInstanceId, attachment);
  4. if(srcDocument==null){
  5. throw new ConnectorException("Unable to retrieve attachment referenced by " + attachment);
  6. }
  7. final byte[] content = processAPI.getDocumentContent(srcDocument.getContentStorageId());
  8. final ByteArrayInputStream inputStream = new ByteArrayInputStream(content);
  9. String fileName = srcDocument.getContentFileName();
  10. String mimeType = srcDocument.getContentMimeType();

Then you have to read this stream to write a file on your drive.

Comments

Submitted by aCordier on Wed, 08/06/2014 - 08:53
Submitted by Sean McP on Wed, 11/05/2014 - 05:05

The code above seems to be sending a file up, not bringing it down to the PC,. Do you have an example of this, if possible while also using the File/Directory dialog to ask where to put the document...

Thanks

Notifications