0

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.

chris_dev
  • 1
  • 1

1 Answers1

0

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.

  • Thanks for your response. I'll try this approach. Thank you – chris_dev May 11 '23 at 01:23
  • Did you have any luck? If so, please mark my answer as accepted. If not, let me know what the issue is and I'll try to amend the answer. – Andrew W Jun 17 '23 at 02:47
  • Hi Sir @Andrew. Sorry for the late response. I haven't access again bonita as i shift again on a different assignment.But anyway i will try within this week to try your suggestion and provide the necessary rating. Again thank you for your effort and follow-up on this. – chris_dev Jun 19 '23 at 05:12