# Save Attachment File in a disk

**URL:** <https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681>\
**Category:** Q&A\
**Created:** [9 June 2014 19:34 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681 "2014-06-09T19:34:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ale.ghirardi](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@ale.ghirardi](https://community.ofelia.com/u/ale.ghirardi)\
**Post date:** [9 June 2014 19:34 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/1 "2014-06-09T19:34:46Z")

</div>

Hello, I need to save attachments that are loaded into the process on the hard drive of the computer.  
Someone can help me?

Thank you

Greetings.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [16 June 2014 14:42 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/2 "2014-06-16T14:42:17Z")

</div>

An easy way would be to add a script saving your file from the output operation of the file widget:

`
try
{
 FileOutputStream fos = new FileOutputStream("c:\\temp\\storeThis.text");
  fos.write(field_File1.getContent());
  fos.close();
}
catch(FileNotFoundException ex)
{
 System.out.println("FileNotFoundException : " + ex);
}
catch(IOException ioe)
{
 System.out.println("IOException : " + ioe);
}
`

I’m attaching an example.  
[http://we.tl/wKIsY6isLm](http://we.tl/wKIsY6isLm)

---

<div class="post-metadata">

**Author:** ![ale.ghirardi](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@ale.ghirardi](https://community.ofelia.com/u/ale.ghirardi)\
**Post date:** [16 June 2014 20:54 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/3 "2014-06-16T20:54:57Z")

</div>

I feel the same as a kkpatel. And when I run the process after having created the groovy connector with the code I do not save the attachment

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [19 June 2014 18:29 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/4 "2014-06-19T18:29:49Z")

</div>

Hi,

Here is a version developed using 6.3.1.  
[http://we.tl/Tvvnhyk8sN](http://we.tl/Tvvnhyk8sN)

I hope it helps 🙂

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [10 June 2014 20:53 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/5 "2014-06-10T20:53:44Z")

</div>

Hi,

Which version of Bonita are you using?

---

<div class="post-metadata">

**Author:** ![ale.ghirardi](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@ale.ghirardi](https://community.ofelia.com/u/ale.ghirardi)\
**Post date:** [10 June 2014 21:11 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/6 "2014-06-10T21:11:54Z")

</div>

Bonita BPM 6.3 comunity version

---

<div class="post-metadata">

**Author:** ![kppatel](https://avatars.discourse-cdn.com/v4/letter/k/ecccb3/32.png) [@kppatel](https://community.ofelia.com/u/kppatel)\
**Post date:** [16 June 2014 18:26 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/7 "2014-06-16T18:26:43Z")

</div>

Hello i m using also 6.3 community . when i try to import process it give : Incompatible version error .  
what should i do ?

i have same issue and i really need it thanks

---

<div class="post-metadata">

**Author:** ![kppatel](https://avatars.discourse-cdn.com/v4/letter/k/ecccb3/32.png) [@kppatel](https://community.ofelia.com/u/kppatel)\
**Post date:** [16 June 2014 18:35 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/8 "2014-06-16T18:35:58Z")

</div>

Pl look following screenshot :

![f](http://i.imgur.com/zfoLuKN.png)

error as follow :

![eror](http://i.imgur.com/66SM4yk.png)

---

<div class="post-metadata">

**Author:** ![ale.ghirardi](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@ale.ghirardi](https://community.ofelia.com/u/ale.ghirardi)\
**Post date:** [19 June 2014 15:00 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/9 "2014-06-19T15:00:12Z")

</div>

Please copy the Bonita Engine log to see the error must

---

<div class="post-metadata">

**Author:** ![danilo.martino](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@danilo.martino](https://community.ofelia.com/u/danilo.martino)\
**Post date:** [28 August 2014 13:51 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/10 "2014-08-28T13:51:03Z")

</div>

Hello I am using Bonita Community Edition v. 6.3.

How can I retry a document saved on hard drive by the groovy script posted above by francois.chevresson?

Carry the code below:  
`
try
{
FileOutputStream fos = new FileOutputStream(“c:\temp\storeThis.text”);
fos.write(field_File1.getContent());
fos.close();
}
catch(FileNotFoundException ex)
{
System.out.println("FileNotFoundException : " + ex);
}
catch(IOException ioe)
{
System.out.println("IOException : " + ioe);
}
`

I have configured a form in which I created an input field;  
in the **Data** section I have setted these **Data Decriptions** :

- ‘ **download** only’ clicked
- ‘ **initial value** ’ setted to ‘Document’;

Although this configuration, I don’t found - in Client Portal - link to retry original document saved on hard drive.

For completeness I show you the groovy script used to retry document link:  
`
String path = “correct_path” +variable_storing_field_File1.getFileName();
return path;
`

@francois.chevresson Please, could you share this example again?

Thank you for all.

Best regards.

---

<div class="post-metadata">

**Author:** ![sam87](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@sam87](https://community.ofelia.com/u/sam87)\
**Post date:** [3 January 2015 05:15 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/11 "2015-01-03T05:15:15Z")

</div>

@francois.chevresson Please, could you share this example again?

I tried to download it but it doesn’t seems to be available yet…

Best regards.

---

<div class="post-metadata">

**Author:** ![claz08](https://avatars.discourse-cdn.com/v4/letter/c/5e9695/32.png) [@claz08](https://community.ofelia.com/u/claz08)\
**Post date:** [19 July 2016 15:49 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/12 "2016-07-19T15:49:02Z")

</div>

hi , i really need this example , please if there anyone that have this example , plese share it!

---

<div class="post-metadata">

**Author:** ![Giro1981](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@Giro1981](https://community.ofelia.com/u/Giro1981)\
**Post date:** [29 June 2014 18:43 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/13 "2014-06-29T18:43:37Z")

</div>

Please, could you share this example again?

I tried to download it but it doesn’t seems to be available yet…

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [30 June 2014 19:59 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/14 "2014-06-30T19:59:40Z")

</div>

Here you go:  
[http://we.tl/hn3ZuGfIpc](http://we.tl/hn3ZuGfIpc)

---

<div class="post-metadata">

**Author:** ![Giro1981](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@Giro1981](https://community.ofelia.com/u/Giro1981)\
**Post date:** [30 June 2014 21:54 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/15 "2014-06-30T21:54:52Z")

</div>

Many thanks!

---

<div class="post-metadata">

**Author:** ![Giro1981](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@Giro1981](https://community.ofelia.com/u/Giro1981)\
**Post date:** [1 July 2014 07:49 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/16 "2014-07-01T07:49:41Z")

</div>

Hi François,

If I’m not wrong in this example file is saved in disk getting content directly from form field:  
fos.write(field\_File1.getContent());

But, what could I do if I want get contet from internal document associated with case? I have an acitivity at the end of the process that it should save in disk all documents attached during the process in previous tasks.

Could you help me about which api class I have to use to do that?

Thanks in advance,

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [2 July 2014 19:42 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/17 "2014-07-02T19:42:43Z")

</div>

Hi,

You can retrieve all the documents attached to the process instance using the processApi method:  
[http://documentation.bonitasoft.com/javadoc/api/6.0/sp/common/org/bonitasoft/engine/api/DocumentAPI.html#getLastVersionOfDocuments](http://documentation.bonitasoft.com/javadoc/api/6.0/sp/common/org/bonitasoft/engine/api/DocumentAPI.html#getLastVersionOfDocuments)(long, int, int, org.bonitasoft.engine.bpm.document.DocumentCriterion)

From the document, you can get the storageId use to retrieve the content using getDocumentContent

---

<div class="post-metadata">

**Author:** ![Giro1981](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@Giro1981](https://community.ofelia.com/u/Giro1981)\
**Post date:** [3 July 2014 08:11 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/18 "2014-07-03T08:11:12Z")

</div>

Thanks,  
I’ll try it, but do you know what values have to be set in fields “int pageIndex, int numberPerPage”?

API describes them as:  
pageIndex - The index of the page  
numberPerPage - The number of documents to list per page

but I’m not quite sure that it means.

Thanks for your help,

---

<div class="post-metadata">

**Author:** ![ale.ghirardi](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@ale.ghirardi](https://community.ofelia.com/u/ale.ghirardi)\
**Post date:** [24 June 2014 21:44 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/19 "2014-06-24T21:44:10Z")

</div>

The file is saved correctly, but I need to continue appearing in other forms to download

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [24 June 2014 21:58 UTC](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681/20 "2014-06-24T21:58:26Z")

</div>

in that case return the name of the document from the groovy script instead of a boolean and assign the result of the operation to a Document variable in bonita.

[Next page](https://community.ofelia.com/t/save-attachment-file-in-a-disk/4681.md?page=2)
