# uploading another doc in the same process

**URL:** <https://community.ofelia.com/t/uploading-another-doc-in-the-same-process/8719>\
**Category:** Q&A\
**Created:** [5 September 2017 23:15 UTC](https://community.ofelia.com/t/uploading-another-doc-in-the-same-process/8719 "2017-09-05T23:15:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alberto\_108](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@alberto\_108](https://community.ofelia.com/u/alberto_108)\
**Post date:** [5 September 2017 23:15 UTC](https://community.ofelia.com/t/uploading-another-doc-in-the-same-process/8719/1 "2017-09-05T23:15:58Z")

</div>

Hi everybody,

I’m having problems uploading new docs using the API from Bonita. Let me explain my case.  
I have a process where the user can upload some files at the instantation form and it works fine, but in some cases, they need to upload more files in other Tasks. And it is here where the problems arrive

- The first problem is that I can not link a Doc object to a contract from this task (as I did in the instantation ofrm),
- so I am trying to do it as it seems it use to be done with older versions, using the attachDocument method form the DocumentAPI lib, and i’m getting always the same error message : “\*\*No signature of method: static org.bonitasoft.engine.api.DocumentAPI.attachDocument() is applicable for argument types: (java.lang.Long, java.lang.String, java.lang.String, java.lang.String, [B)\*\*” The extrange thing is that if I look into the Bonita Doc is says that the attachDocument has the following parameters: “Document attachDocument(long processInstanceId, String documentName, String fileName, String mimeType, byte documentContent)  
throws ProcessInstanceNotFoundException,  
DocumentAttachmentException”

The source code of my operation is:

import java.util.logging.Logger  
import org.bonitasoft.engine.api.DocumentAPI

Logger logger= Logger.getLogger(“org.bonitasoft”)  
logger.info(“INFO Trace Start\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*”)  
masFotos.each{  
logger.info("it.getFileName = " + it.getFileName())  
logger.info("it.Content Size = " + it.getContent().size())  
DocumentAPI.attachDocument( processInstanceId, it.getFileName(), it.getFileName(), “image/jpeg”, it.getContent())  
logger.info(“It should arrive here if it wrorks, but it seems it doesn’t”)  
}

Does anyone knows whats wrong with it?

Thank you very much,  
Best Regards  
Alberto

---

<div class="post-metadata">

**Author:** ![rjrjswrdvi](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@rjrjswrdvi](https://community.ofelia.com/u/rjrjswrdvi)\
**Post date:** [20 April 2018 18:36 UTC](https://community.ofelia.com/t/uploading-another-doc-in-the-same-process/8719/2 "2018-04-20T18:36:51Z")

</div>

Hello,

I would suggest this way and I have verified this approach(on Bonita 7.5.4).

1. In the _Operations_ of the human task, add an operation with the below script(on the right-hand side)  
If `taskFile` is the task contract input,  
`return apiAccessor.processAPI.attachDocument(processInstanceId,<unique name for this document> ,taskFile.fileName , taskFile.contentType, taskFile.content).id.toString();`

NOTE: The second parameter which is the document variable name must be unique for each operation, otherwise, Bonita throws an exception that the document is already existing unless you want to [update that existing document](https://documentation.bonitasoft.com/bonita/7.5/handling-documents#toc3) .

1. For the above operation, select a task/process variable on the left-hand side. → this is to make the operation complete with no validation errors in the studio. You can use this variable as needed(or any other variable returned from the above engine API call). As this is a Human task, BPMN would give an INFORMATION in _Validation status_, if the above logic is performed in a script in the ‘Connectors out’ as a BPMN2 compliant issue.

2. Finally, in order to check if the document has been successfully attached to the case, we can use the below REST URL( if the case is still active. Otherwise get [archived document](https://documentation.bonitasoft.com/bonita/7.6/bpm-api#toc18) )

`../API/bpm/caseDocument?p=0&c=100&f=caseId=<caseId>`

---

<div class="post-metadata">

**Author:** ![Dibyajit.Roy](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@Dibyajit.Roy](https://community.ofelia.com/u/Dibyajit.Roy)\
**Post date:** [7 September 2017 14:51 UTC](https://community.ofelia.com/t/uploading-another-doc-in-the-same-process/8719/3 "2017-09-07T14:51:47Z")

</div>

Hello

I think you need to import more classes for it to work.

I use the Below code for Documents. Have a look,

import org.bonitasoft.engine.bpm.document.Document;  
import org.bonitasoft.engine.bpm.document.DocumentValue;  
import org.bonitasoft.engine.bpm.contract.FileInputValue;

List documentsMerged = new ArrayList();  
DocumentValue dv;

if(hlsDoc)  
{  
hlsDoc.each { pj → // pj is a FileInputValue}  
dv = new DocumentValue( pj.getContent(), null, pj.getFileName() );  
documentsMerged.add(dv); }

```
return documentsMerged;

```

}

Hope this helps…

---

<div class="post-metadata">

**Author:** ![alberto\_108](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@alberto\_108](https://community.ofelia.com/u/alberto_108)\
**Post date:** [8 September 2017 19:06 UTC](https://community.ofelia.com/t/uploading-another-doc-in-the-same-process/8719/4 "2017-09-08T19:06:24Z")

</div>

Hello Dibyajit,

Thanks for your answer.  
I was trying to use the DocumentValue class but the problem is that after executing the operation I can not see the document content in the “document” table at the BonitaJournal database.

What should I do after creating a DocumentValue object to see the document added into the “document” table?

Thank you!!!  
Alberto

---

<div class="post-metadata">

**Author:** ![Dibyajit.Roy](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@Dibyajit.Roy](https://community.ofelia.com/u/Dibyajit.Roy)\
**Post date:** [10 September 2017 14:21 UTC](https://community.ofelia.com/t/uploading-another-doc-in-the-same-process/8719/5 "2017-09-10T14:21:14Z")

</div>

Actually I dont use a table to store documents.  
I create a Document variable in the Studio. I believe the Docs are saved in a particular location on server.  
I can access these docs using Rest API.  
So basically I use the Operation section for each task.  
Left hand side has the Doc and right side section has value set as Script. There I use the above code.

regards
