gpt4 book ai didi

postgresql - 在 Play 1.2.4 Framework 中显示 BLOB 图片

转载 作者:行者123 更新时间:2023-11-29 12:47:30 27 4
gpt4 key购买 nike

我正在做这个项目,我必须存储用户的信息,包括他的图像。我将它作为 blob 图像存储在数据库中。如果“照片”是我的图像列,那么当我在网页中呈现其他列时,例如:“render.column_name”它工作正常。但是当我为图像(如“render.photo”)执行此操作时,数据库会在我的网页中返回“jpa.blob .....”。谁能帮我显示存储在数据库中的这张图片?

最佳答案

您需要一个单独的 Controller 方法来提供图像数据。 Controller 可能看起来像这样,假设您有一些关于文件的元信息,即 mime 类型,在自定义实体 FileStore 中。

public class ShowFile extends Controller {
public static void render(String id) {
FileStore fs = // fetch the file out of the DB using the id

notFoundIfNull(fs);

response.setContentTypeIfNotSet(fs.mimeType);
response.setHeader("Cache-Control", "public, max-age=31536000");
renderBinary(new ByteArrayInputStream(fs.content), fs.content.length);
}
}

在页面中,您将使用 img 标记链接到该方法:

<img src="@{ShowFile.render(image.id)}" /> 

关于postgresql - 在 Play 1.2.4 Framework 中显示 BLOB 图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11952588/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com