无法在 gwt google 数据存储中获取图像数据 - 图像被拉伸

发布于 2024-08-17 01:28:29 字数 1318 浏览 5 评论 0原文

我有一个类,在其中声明了一个序列化类来存储图像数据

@Persistent(序列化=“true”)
私有可下载文件 imageLogoFile;

类的实现

public class DownloadableFile implements Serializable {

public DownloadableFile(byte[] content, String filename, String mimeType) { 极好的(); this.内容=内容; this.文件名=文件名; this.mimeType = mimeType; } 私有静态最终长serialVersionUID = -8497358622042084708L; 私有字节[]内容; 私有字符串文件名; 私有字符串 mimeType; 公共下载文件(){ } showlogo

是一个 servlet,它应该从数据存储区获取内容,但它的所有调用都返回 null,而 blob 在 appwrench 中可见。

预期影响图像数据的位置

final Image logoImage = new Image();
logoImage.setUrl("/showlogo");
logoImage.setHeight("100px");
logoImage.setWidth("100px");

编辑: 现在正在保存和获取图像数据,但图像被拉伸。我尝试过给出高度/宽度等,

Servlet 代码:

com.sms.DownloadableFile df = w.getImageLogoFile();
if (df != null){
    String filen = df.getFilename();
    response.setHeader("Content-Disposition", "filename="+filen);
    String mime = df.getMimeType();
    response.setContentType(mime);
    byte[] b = df.getContent();
    //Base64.encode(b);
    response.setContentLength(b.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(b);
    // Pipe data here
    out.flush();
    out.close();
}

I have a class in which I have decrlared a serialized class to store image data

@Persistent(serialized = "true")
private DownloadableFile imageLogoFile;

Implementation of the class

public class DownloadableFile implements Serializable {

public DownloadableFile(byte[] content, String filename, String mimeType) {
super();
this.content = content;
this.filename = filename;
this.mimeType = mimeType;
}
private static final long serialVersionUID = -8497358622042084708L;
private byte[] content;
private String filename;
private String mimeType;
public DownloadableFile() {
}
}

showlogo is a servlet that is supposed to fetch content from datastore but all its call are returning null whereas the blob is visible in appwrench.

Place where its expected to fecth the image data

final Image logoImage = new Image();
logoImage.setUrl("/showlogo");
logoImage.setHeight("100px");
logoImage.setWidth("100px");

Edit :
Now the image data is getting saved and fetched but the image is stretched out. I have tried giving height/width etc.,

Servlet code :

com.sms.DownloadableFile df = w.getImageLogoFile();
if (df != null){
    String filen = df.getFilename();
    response.setHeader("Content-Disposition", "filename="+filen);
    String mime = df.getMimeType();
    response.setContentType(mime);
    byte[] b = df.getContent();
    //Base64.encode(b);
    response.setContentLength(b.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(b);
    // Pipe data here
    out.flush();
    out.close();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌味 2024-08-24 01:28:29

并且您没有将该字段放入提取组中,因此不会提取它。

and you didn't put that field in the fetch group, so it isn't fetched.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文