# How to Store attachment into hard drive .

**URL:** <https://community.ofelia.com/t/how-to-store-attachment-into-hard-drive/4939>\
**Category:** Q&A\
**Created:** [4 August 2014 09:55 UTC](https://community.ofelia.com/t/how-to-store-attachment-into-hard-drive/4939 "2014-08-04T09:55:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![er.erikndp](https://avatars.discourse-cdn.com/v4/letter/e/b2d939/32.png) [@er.erikndp](https://community.ofelia.com/u/er.erikndp)\
**Post date:** [4 August 2014 09:55 UTC](https://community.ofelia.com/t/how-to-store-attachment-into-hard-drive/4939/1 "2014-08-04T09:55:35Z")

</div>

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 .

---

<div class="post-metadata">

**Author:** ![aCordier](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aCordier](https://community.ofelia.com/u/aCordier)\
**Post date:** [6 August 2014 06:52 UTC](https://community.ofelia.com/t/how-to-store-attachment-into-hard-drive/4939/2 "2014-08-06T06:52:13Z")

</div>

Hello,

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

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

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

---

<div class="post-metadata">

**Author:** ![aCordier](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@aCordier](https://community.ofelia.com/u/aCordier)\
**Post date:** [6 August 2014 06:53 UTC](https://community.ofelia.com/t/how-to-store-attachment-into-hard-drive/4939/3 "2014-08-06T06:53:45Z")

</div>

Maybe this will help:

[https://github.com/a-cordier/bonita-connector-nuxeo/blob/master/bonita-connector-nuxeo-upload-impl/src/main/java/fr/univlille2/bpm/NuxeoUploadConnector.java](https://github.com/a-cordier/bonita-connector-nuxeo/blob/master/bonita-connector-nuxeo-upload-impl/src/main/java/fr/univlille2/bpm/NuxeoUploadConnector.java)

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [5 November 2014 04:05 UTC](https://community.ofelia.com/t/how-to-store-attachment-into-hard-drive/4939/4 "2014-11-05T04:05:54Z")

</div>

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
