Save attach file in a file server or other local location in Bonita soft

114 Views Asked by At

I'm currently studying this bonitasoft and having difficulty in the attach file on where it is located after being submitted and how to retrieve it on a different process flow.

I tried the examples on file attachment but i'm unable to trace on where it is located. Can the attach file be saved or be transferred into a different location (saving the path in the BDM/database for reference and use for other activity). Need a sample snippet/code to be able to understand the routine.

Thank you in advance.

1

There are 1 best solutions below

3
On

I use the Sardine WebDAV library and a Nextcloud server to achieve this.

Here's a sample Groovy script, to upload the content of a Bonita Document object to a Nextcloud server:

import com.github.sardine.*

// a short function to modify URLEncoder.encode's output to make filename spaces %20 instead of +
String encodeURL(String url) {
    String u = URLEncoder.encode(url,"UTF-8").replace("+", "%20")
    return u
}

String webpath = "https://your.nextcloud.server/remote.php/dav/files/(...)"

Sardine dav = SardineFactory.begin(webdavUser, webdavPassword)
dav.enablePreemptiveAuthentication("your.nextcloud.server")

// you'll want to things like verify or create the path to the upload point if necessary
if (!dav.exists(webpath)) {
    dav.createDirectory(webpath))
}

Document doc = yourBonitaDocument

// store the document data in a byte object
byte[] docData = apiAccessor.getProcessAPI().getDocumentContent(doc.contentStorageId)

// Now upload the file to webpath
// (you'll want a try/catch routine here to handle failures, I've left it out for simplicity)
dav.put(encodeURL(webpath + "/" + doc.contentFileName), docData) // (or of course any another filename if you wish)


This sample depends on the Sardine library so you'll need to add it to your project (Overview > Extensions > Add a custom extension > Other, fill out the Maven details as per the link), and include it as a Java dependency in your process configuration (Configure > Production > Java dependencies > tick "sardine-5.xx.jar").

See also my answer (awnz) in the Bonitasoft forum here.