我无法显示存储为休息服务返回的blob的图像:
这是返回编码到base64中的blob存储图像的其余服务代码:
@GET
@Path("/get")
@Produces("image/jpeg")
public Response getFile() {
String base64 = getStringImage();
ResponseBuilder response = Response.ok((Object) base64);
return response.build();
}
String getStringImage() {
try {
AnounceService anounceService = (AnounceService)getApplicationContext().getBean("AnounceService");
Blob imageBlob = anounceService.getStgImage();
int blobLength = (int)imageBlob.length();
byte[] buff = imageBlob.getBytes(1, blobLength);
String base64=Base64Utils.toBase64(buff);
return base64;
} catch (Exception exc) {
}
return null;
}
这是gwt客户端代码,无法显示上述其余代码返回的图像: String url =" root / api / image / get&#34 ;; 最终RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,url); Image img;
builder.setCallback(new RequestCallback(){
public void onResponseReceived(final Request request, final Response response) {
if (response.getStatusCode() == Response.SC_OK) {
final HTML imageHolder = new HTML();
String base64 = response.getText();
String imgTag = "<img src='data:image/gif;base64,"+base64+"' />'";
imageHolder.setHTML(imgTag);
RootPanel.get().add(imageHolder);
}
}
没有触发任何错误,但我没有看到浏览器中显示的任何图片。