I am getting a base64 byte[] from an xml file via jaxb and I am not sure how to convert this back to an gwt image (which is basically an underlying html img if I understood that correctly). How do I convert into the proper string?
My first instinct was to
public void onSuccess(final byte[] icon) {
img.setUrl("data:image/png;base64,"+icon.toString());
but obviously that does not work. Any help is appreciated!
If you want to use data URIs (with base64 encoding) - although IE <=7 doesn't support it, and IE8 only allows up to 32 kB - you'll have to base64-encode the image data.
There are several Base64 encoders around e.g. com.google.gwt.user.server.Base64Utils
, which you can use on the server side:
String base64 = Base64Utils.toBase64(icon);
Then transfer the encoded data to the client.
If you absolutely want to, you could also use the encoder on the client side, but that would require to copy the java file to the client source (if you make sure that the implementation you choose allows that).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With