how to add an attached file in bonita?

Hi , i woludl like to add an attached file and i want to save the name of file in a database and finally to save it in a location of computer.

somebody has an idea?

regards.

Please someone answer this , i need it as well.

Programatically, you can attach a document with

ProcessAPI
Document addDocument(
long processInstanceId,
String documentName,
String description,
DocumentValue documentValue)

Note that documentName is name of Bonita’s document variable name

org.bonitasoft.engine.bpm.document.DocumentValue constructor can be with

public DocumentValue(byte content, String mimeType, String fileName)

take in count mimeType, you can check a ful list in
mimeType

After adding the document, with the Document response, you can get the full information of the attached file; maybe you can store doc.getId() or doc.getUrl(). Url is the relative path, so you can expose it as html link.

Here’s an example.

import org.bonitasoft.engine.bpm.document.DocumentValue
import org.bonitasoft.engine.bpm.document.Document

// read file
FileInputStream fis = new FileInputStream(“c:\temp\file.txt”)
byte bytes = new byte[fis.available()]
fis.read(bytes)
fis.close()

// create DocumentValue
DocumentValue dv = new DocumentValue(bytes, “text/plain”, “file.txt”)
// add document
Document doc = apiAccessor.getProcessAPI().addDocument(processInstanceId, “docs”, “Description”, dv)

// manipulate response
return doc.getId() + " " + doc.getContentFileName() + " " + doc.getUrl()

Ok, you can add a Groovy Out Connector in the Human Actiity, but this time you may use

// query document
Document doc = apiAccessor.getProcessAPI().getLastDocument(long processInstanceId, String documentName)
// manipulate response
return doc.getId() + " " + doc.getContentFileName() + " " + doc.getUrl()

take a look at ProcessAPI, theres more Document query functions

i’m very confuse, please, can you tel me all the steps, that is , firstly , i can to create the attached widget, afterwards create a variable (wihch is the type of variable that i have to use). and so on…

Thanks for the exmple , but what i’m looking for is a way to use the attached widget in order to do what i said before. That is , the user will select a file throught this widget and from there , to get the name of this file recently uploaded and move it to another path either a local path or an external path.

if you have not understood well , please say me where i can implement the code that you shown me
regards