DB or 서버 파일에 Image 데이터를 GWT의 image 객체에 보여줘야하는 경우가 있다.
image를 inputstream으로 읽어봐서 client에 rpc를 이용해서 보내지는 못한다.
이럴 때 Base64를 사용하면 된다.
서버측 코드
private static String convertToBase64(InputStream in) throws IOException {
String base64 = Base64.encodeBase64String(IOUtils.toByteArray(in));
String imgBase64="https://t1.daumcdn.net/cfile/tistory/214FEB3856EA362E2B"+base64;
return imgBase64;
}
InputStream은 Image를 읽은 데이터이다.
이것을 Byte Array로 변겨해준다.
IOutils : org.apache.commons.io.IOUtils
Base64 : org.apache.commons.net.util.Base64
client 코드.
public class ServerImage extends Image {
public ServerImage(String imageUrl, String width, String height) {
String styleName = this.getStyleName();
this.setStyleName(styleName);
this.setUrl(imageUrl)
this.setSize(width, height);
}
}
빨갠색 부분이 중요하다.
'나는개발자다 > GWT' 카테고리의 다른 글
javascript에서 GWT 메소드 호출방법. (0) | 2015.06.17 |
---|---|
모바일 웹에서 sms, email 연동시키기. (0) | 2015.06.17 |
gwt label에서 text에 맞게 label width 조절하기. (0) | 2013.07.08 |
GWT, TinyMCE Editor 연동. (0) | 2012.05.28 |
GWT를에서 Drag and Drop (0) | 2012.03.21 |