I am trying to start a process via REST with several variables. All other variables work fine, except for my image. This is my variable definition in JavaScript
"imageBase64": {
value: imageAsBase64String,
type: "File",
valueInfo: {
filename: "image.jpg",
mimetype: "image/jpeg",
encoding: "UTF-8"
}
}
Here, my value looks like data:image/jpeg;base64,/9j/4AAQSkZJRgA...
. This is how I try to read the variable in a Java Worker
FileValue image = this.externalTask.getVariableTyped("imageBase64");
InputStream inputStream = image.getValue();
byte[] byteArray = new byte[inputStream.available()];
inputStream.read(byteArray);
File targetFile = new File("/home/joel/projects/camunda-worker/targetFile.jpg");
OutputStream outStream = new FileOutputStream(targetFile);
outStream.write(byteArray);
outStream.close();
At this point the image writte to disk seems to be garbage, I can’t really even paste it here. I know I am doing something wrong, but I can’t figure out how to do it correctly - any help is very appreciated!