Friday, June 17, 2016

construct image from Serverside to client side in GWT

Hello all,

my requirement is an image getting from server to GWT client.

from the client side, I send a message through AsyncCallBack method and the server response Serializable byte[] object. when getting this object,  I am parsing as String object. but the image could get.

the steps i followed

1.client side  Asynccallback method is

CommandMessage msg = new CommandMessage(itemId, "get-image-data");

cmain.ivClient.execute(msg, new AsyncCallback<ResponseMessage>() {

                public void onFailure(Throwable caught) {
                    //add(new Label("Problem in Getting Map"));


                public void onSuccess(ResponseMessage result) { 
                        here I am getting is "data:india/png;base64,parsedString"     
                        Image image = new Image(;

                        canvas.add(image);                        //but I could not getting Image

2. parsing the byte[] object from serverside

    public cti.gwtdemo.client.rpc.ResponseMessage execute(cti.gwtdemo.client.rpc.CommandMessage commandMessage) throws Exception {
        cti.item_system.CommandMessage cmdMsg = CVT(commandMessage);
        cti.gwtdemo.client.rpc.ResponseMessage rsMsg = CVT(getItemService().execute(cmdMsg));
        byte[] bytes = (byte[]);
        String base64 =;
//here converting process
        String[] s = rsMsg.args[0].split(" ");
        s[0] = s[0].replace(".", "/");               // the string s[0] contains image name with type ie india.png and i replaced as india/png"data:"+s[0]+";base64,"+base64;                                      //"data:images/png;base64," + base64; ---------------------> Actually I stuck here.  ( As per mentioned in )
       (in now contains ......... "data:india/png;base64, parsedString")
         return rsMsg;

 protected cti.item_system.CommandMessage CVT(cti.gwtdemo.client.rpc.CommandMessage cm) {

        return new cti.item_system.CommandMessage(cm.itemId, cm.command, cm.args,;   //Server Side data

    protected cti.gwtdemo.client.rpc.ResponseMessage CVT(cti.item_system.ResponseMessage rm) {

        return new cti.gwtdemo.client.rpc.ResponseMessage(rm.command, rm.itemId, rm.result, rm.args,; //after getting data it set to client side

please Help me, and  what stands for "data:images/png;base64," + base64;

Thanks in Advance

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment