开发者

How to manage Mysql image response in gwt?

开发者 https://www.devze.com 2023-03-07 14:47 出处:网络
I got a problem, I can\'t display an image from my Database in GWT, even when I proved and I could save the image in my computer. Here is the code:

I got a problem, I can't display an image from my Database in GWT, even when I proved and I could save the image in my computer. Here is the code:

        byte[] bytes = new byte[8096];
        int len = 0;

        while ( (len = in.read( bytes ))> 0 )
        {
         开发者_开发知识库   if(!fichero.exists())
            {
                out.write( bytes, 0, len );
            }
        }

        out.flush();
        out.close();
        in.close();
        //byte[] bytes = IOUtils.toByteArray(in);

        String base64 = Base64Utils.toBase64(bytes); 
        //base64 = "data:image/png;base64,"+base64;
        base64 = "data:image/gif;base64,"+base64;
        return base64;

        }
        else
        {
            return "http://cracktouch.com/wp-content/uploads/2011/02/Run-Like-Hell-Deluxe.png";
        }

This code is in the class GreetingServiceImpl. "in" is an Inputstream with the image which is correct because I could save the image in my computer, but I can't display it in GWT when I use the string base64 like this: Image image = new Image(base64); contenido.add(image); Any suggestion?


The bytes array is fixed size and is bigger then the image data - so there are some unused 0s at the end.

Call to Base64Utils.toBase64(bytes) converts the whole array including unused data to string.

Either trim the array or use a Base64 implementation where you can specify size of input data.

0

精彩评论

暂无评论...
验证码 换一张
取 消