How can I upload a document to my cloud service? (using webdav)

Hello, in a user task form, I need to upload a document. My NextCloud box is already working but don´t know how to configure it. In UI Designer, added upload widget but the configuration at the proposed connector "CMIS" seems not be compatible with webdav protocol or I am doing something wrong.

Thanks!

Luciano

Hi,

Did you try the REST PUT connector to execute an upload request ?

HTH
Romain

Sharing the answer I found:

 

I am using the Sardine Java WebDAV client to handle interactions between Bonita and Nextcloud. It's surprisingly easy, and the upload is achieved with just a couple of lines of code.

It's in Maven here. You need to add it as a Maven extension to use.

import com.github.sardine.* // WebDAV library
import com.github.sardine.impl.SardineException
(...)
Sardine dav = SardineFactory.begin(nextcloudUsername, nextcloudPassword)
dav.enablePreemptiveAuthentication("your.nextcloud.server.name") // it seems uploads are more reliable this way
if (!dav.exists(folderPath)) {
     dav.createDirectory(folderPath)
}

dav.put(folderFullURL + "/" + docFilename, apiAccessor.getProcessAPI().getDocumentContent(doc.id.toString())) // upload a document
 

You do need to make sure your URL paths are properly formatted - I'm using this wee hack (not sure if it's best):

String encodeURL(String url) {
    String u = URLEncoder.encode(url,"UTF-8").replace("+", "%20")
    return u
}

 

Hello, assuming still there is no webdav support in Bonita. Which open source DMS is compatible for uploading documents?

thanks,

Luciano

Thanks for your answer Romain, I can interact with DMS using operating system command line (via curl application), PUT, GET, etc. my difficulty is I am not sure how to configurate Bonita REST connector, java message as error does help how to continue. Is there any guide step by step?

Do you have specific issues configuring the connector ?

Hi @awnz,

I have added sardine extension from maven repository into Bonita via this way:

Overview -> Add a custom extension -> Other... -> From a Repository:

    <groupId>com.github.lookfirst</groupId>
    <artifactId>sardine</artifactId>
    <version>5.10</version>

and, I defined the groovy script for Connectors Out for human task upload documents:

import org.slf4j.Logger
import org.slf4j.LoggerFactory
import com.github.sardine.*

Logger LOGGER = LoggerFactory.getLogger("mycompany")
LOGGER.info("the claims in sardine: ${claims.get(0)}")
LOGGER.info("the claimsDocumentInput in sardine: ${claimsDocumentInput.get(0)}")

Sardine dav = SardineFactory.begin('myusername', 'mypassword')

dav.enablePreemptiveAuthentication("mynextcloudserver") // it seems uploads are more reliable this way
if (!dav.exists('Documents/1')) {
     dav.createDirectory('Documents/1')
}

def doc = claims.get(0)
LOGGER.info("the doc in sardine: ${doc}")

dav.put('Documents/1' + "/" + 'test2027.txt', apiAccessor.getProcessAPI().getDocumentContent(doc.id.toString())) // upload a document

But, I got this error after submitted task:

Script1.groovy: 17: unable to resolve class Sardine
 @ line 17, column 9.
   Sardine dav = SardineFactory.begin('myusername', 'mypassword')
           ^

1 error

    wrapped by org.bonitasoft.engine.connector.ConnectorException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 17: unable to resolve class Sardine
 @ line 17, column 9.
   Sardine dav = SardineFactory.begin('myusername', 'mypassword')
           ^

1 error

    wrapped by org.bonitasoft.engine.connector.exception.SConnectorException: org.bonitasoft.engine.connector.ConnectorException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 17: unable to resolve class Sardine
 @ line 17, column 9.
   Sardine dav = SardineFactory.begin('myusername', 'mypassword')
           ^

1 error

    wrapped by org.bonitasoft.engine.commons.exceptions.SBonitaRuntimeException: org.bonitasoft.engine.connector.exception.SConnectorException: org.bonitasoft.engine.connector.ConnectorException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 17: unable to resolve class Sardine
 @ line 17, column 9.
   Sardine dav = SardineFactory.begin('myusername', 'mypassword')
           ^

1 error

 exception was generated here:Script1.groovy: 17: unable to resolve class Sardine
 @ line 17, column 9.
   Sardine dav = SardineFactory.begin('myusername', 'mypassword')
 

Could you please share the way that you use sardine in your Bonita's project?

I'm using Bonita community 2022.1 and Sardine 5.10.

Thank you a lot,

Tam

Hi Tam,

Did you include Sardine as a Java dependency for your process?

Open your process > "Configure" toolbar button > (Local|Qualification|Production (probably all in turn)) > Java dependencies > check if Sardine is listed, otherwise select Others then click Add and find Sardine.

Thanks

Thanks a lot for your response, @awnz. I will try your way.

BTW, I fixed this issue by declare sardine jar file in this path: C:\BonitaStudioCommunity-2022.1-u0\workspace\tomcat\server\webapps\bonita\WEB-INF\lib

Tam.

 

Hi, from my understanding your method would work for Studio, but would need to be repeated for Bonita Engine once you published your project to a server, and possibly repeated on every upgrade.

The Process Configuration method is a little tedious in that it has to be done for every environment (Local, Qualification, Production + any custom ones you make) for every process you have that needs Sardine, but once that's done, it won't need repeating.

 

Cheers

Yes, I think the libs that we declared in Bonita studio, they're used while compiling.

But, while runtime, they're not using.

So, that why we need to declared them again in server lib folders.

Thank you,

Tam

Please follow the documentation guidelines to include an external dependency in a process.