GWT - 来自数据库的图像 [英] GWT - image from database

查看:147
本文介绍了GWT - 来自数据库的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上在一个基于GWT的网站上工作。
现在我坚持我应该如何显示存储在我的网站上的数据库中的图像。

I'm actually working on a GWT based website. Now I'm stuck on how I should display images stored in a database on my website.

基本上我有一个bytearray在我的数据库,我fetch使用hibernate。
现在我应该可以创建一个...标签的数据,但我不知道如何

Basically I've a bytearray in my database, which I fetch using hibernate. Now should I probably create an ... tag out of that data, but I don't know how

我在Java和Hibernate中使用GWT

I'm using GWT in Java and Hibernate

推荐答案

这里是解决方案。首先,您应该使用com.google.gwt.user.server.Base64Utils.toBase64(byte [])对字节数组进行编码。但这种方法不工作的IE 7和IE8有32kb的限制。IE9没有这个限制。

Here is the solution. First you should encode the byte array by using com.google.gwt.user.server.Base64Utils.toBase64(byte[]) . But this method does not work for IE 7. and IE8 has 32kb limit.. IE9 does not have this limit.

这里是服务器上的方法

public String getImageData(){
      String base64 = Base64Utils.toBase64(imageByteArray); 
      base64 = "data:image/png;base64,"+base64;
      return base64;
}

这里是客户端方法;

@Override 
public void onSuccess(String imageData) {     
    Image image = new Image(imageData);     
    RootPanel.get("image").add(image); 
} 

这篇关于GWT - 来自数据库的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆