Hi guys,
we are writing a plugin for AwareIM 5.8 to convert a base64 String to a image.
I'm able to convert the string to an image and create a local file. However I would like
to update the image attribute in the application with the new converted image. I understand
that I need to use the setBinaryMethod but can't get it to work properly. I get the following
error:
com.bas.basserver.executionengine.ExecutionException: Internal error. Error writing attribute
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near '[B@1bafb1b WHERE ID=31' at line 1
Would appreciate any help or examples.
==== Here is my execute method =====
@Override
public Object execute(IExecutionEngine engine, Object[] parameters)
throws SuspendProcessException, ExecutionException,
AccessDeniedException {
if (parameters == null || parameters.length != 1
|| !(parameters[0] instanceof IEntity)) {
return null;
}
IEntity entity = (IEntity) parameters[0];
String base64ImageString = "";
try {
base64ImageString = (String) entity
.getAttributeValue("Base64ImageString");
base64ImageString = base64ImageString.substring(
base64ImageString.indexOf(",") + 1,
base64ImageString.length());
byte[] imageByteArray = decodeImage(base64ImageString);
//Test if image is converted => this works
/*
* FileOutputStream imageOutFile = new FileOutputStream(
* "DecodedImage.png");
*
* imageOutFile.write(imageByteArray);
*
* imageOutFile.close();
*/
//Set Picture Attribute in object
engine.setBinaryData(engine.getExecutionContext(this).getProcess(),
entity.getName(), entity.getId(), "DecodedImage",
imageByteArray);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static byte[] decodeImage(String imageDataString) {
try {
return Base64.decode(imageDataString);
} catch (Base64Exception e) {
e.printStackTrace();
}
return null;
}
Thanks
Werner