In my use case, the image byte data is available as byteArray and has to be passed as a string (not directly as byte[]).
byte[] byteArray = stream.toByteArray