@choibc @douglascrp @fherpertz
Okay i put together a little example.
My usual preference is to use JavaScript for scripting, but Groovy has cleaner syntax for converting Bytes to Base64.
So here is a simple example that allows you to set a document name and upload a file as part of the Start Event. (You can make it a User Task as well if you like).
Then there is a script task (using JS) to get a bunch of “metadata” about process instance.
Then there is a Service Task that combines the File Name, Metadata, and upload file into a POST to a API. For this example i created a sample api end point with Deployd and created a resource (/ecm) with 3 fields: fileData, fileName, processInfo.
I used execution.getVariableTyped("Document").getValue()
to get the file as a Bytes
object, and then built a groovy object, and then converted the object to JSON.
import groovy.json.JsonOutput
def doc = execution.getVariableTyped("Document").getValue()
def obj = new LinkedHashMap();
obj.fileData = doc.bytes.encodeBase64().toString()
obj.fileName = execution.getVariable("DocumentName")
obj.processInfo = execution.getVariable("ProcessMetadata")
JsonOutput.toJson(obj)
I wanted to do all of this as part of the “payload” so that we were not storing any camunda process variables of the files as strings (which have a size limit).
@camunda is there a way through the Java API / execution object to get a file as Base64/binary as with the REST API? Could not find the corresponding methods in the javaDocs.
Example files (change .xml file to .html):
fileUpload.xml (408 Bytes)
EcmUploadExample.bpmn (6.9 KB)