Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gwt base64 image

Tags:

base64

gwt

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!

like image 733
Hoax Avatar asked Jun 18 '10 17:06

Hoax


1 Answers

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).

like image 134
Chris Lercher Avatar answered Sep 21 '22 02:09

Chris Lercher