hello People,
I am trying to accept a image file from user and try to read its content for which i am getting the following error
java.io.ByteArrayInputStream cannot be cast to class org.camunda.bpm.engine.variable.value.FileValue (java.io.ByteArrayInputStream is in module java.base of loader ‘bootstrap’; org.camunda.bpm.engine.variable.value.FileValue is in unnamed module of loader ‘app’)
java.lang.ClassCastException: class java.io.ByteArrayInputStream cannot be cast to class org.camunda.bpm.engine.variable.value.FileValue (java.io.ByteArrayInputStream is in module java.base of loader ‘bootstrap’; org.camunda.bpm.engine.variable.value.FileValue is in unnamed module of loader ‘app’)
Thanks @Ingo_Richtsmeier
I have reached till extracting the variable in InputStream but I want to convert that InputStream into File object which is giving me the above error
From my understanding, the problem occurs in the following line:
String result = instance.doOCR(imageFile);
So, the problem is not a Camunda problem — and we can only provide limited help.
I don’t know how Tesseract determines the image format, maybe your imageFile is lacking a proper file extension? Have you tried saving the file and opening it? Can you see the image?
You can try using a BufferedImage instead of file, i.e., converting the ByteArrayInputStream directly to a BufferedImage and passing this image to Tesseract.
Thanks @StephanHaarmann
I did this
Object fileData = delegateExecution.getVariable(“variableName”);
InputStream in = (ByteArrayInputStream) fileData;
BufferedImage bi = ImageIO.read(in);
Sorry, I’m not a Teseract/OCR expert and cannot really help you.
However, I’ve two suggestions to narrow down the error:
Store the image to a file to check whether it got corrupted when uploading/handling it in Camunda
Write a simple Java application without Camunda to check if Tesseract operates as expected.
If both the file looks fine and the output of your simple java application is the same as the result of your Java Delegate, the problem is a Tesseract problem. In this case, you can expect more help from the Tesseract community.