Gwt base64 image

I get the base64 [] byte from the xml file via jaxb, and I'm not sure how to convert it back to a gwt image (which is basically the base html img if I understood this correctly). How to convert to the correct string?

My first instinct was to

public void onSuccess(final byte[] icon) {
img.setUrl("data:image/png;base64,"+icon.toString());

but obviously this does not work. Any help is appreciated!

+5
source share
3 answers

If you want to use a data URI (with base64 encoding), although IE <= 7 does not support it, and only IE8 allows up to 32 KB, you will need to encode base64 image data.

There are several Base64 encoders, for example. com.google.gwt.user.server.Base64Utilswhich you can use on server side:

String base64 = Base64Utils.toBase64(icon);

.

, , java ( , ).

+6
String b = "this should be a base64 encode string that was generated from an icon or byte[]";
Image image = new Image();
image.setUrl("data:image/png;base64,"+b);

view.getPreviewTable().setWidget(14, 0, image);

gwt .

+4

You must provide a URL that you can use to get the image. I really don't think your code will lead to something that looks like a url (something like http: //localhost/myimage.png , or maybe mywebapp / myimage.png ...)

0
source

All Articles