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

1
0
-1

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

Comments

Submitted by lucianoandino.ar on Wed, 12/09/2020 - 03:58

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

thanks,

Luciano

2 answers

1
+1
-1

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
}

Comments

Submitted by tam2022 on Wed, 08/10/2022 - 12:29

Hi @awnz,

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

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

com.github.lookfirst
sardine
5.10

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

Submitted by awnz on Wed, 08/17/2022 - 04:06

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

Submitted by tam2022 on Mon, 08/22/2022 - 05:00

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.

Submitted by awnz on Mon, 08/22/2022 - 20:49

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

Submitted by tam2022 on Tue, 08/23/2022 - 06:23

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

Submitted by romain.bioteau on Tue, 08/23/2022 - 09:06

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

1
0
-1

Hi,

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

HTH
Romain

Comments

Submitted by lucianoandino.ar on Thu, 01/07/2021 - 13:42

<p>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&nbsp;Bonita&nbsp;REST connector, java message as error does help how to continue. Is there any guide step by step?</p>

Submitted by romain.bioteau on Mon, 01/18/2021 - 09:27

Do you have specific issues configuring the connector ?

Notifications