gpt4 book ai didi

java - 将图像保存在 couchbase lite java 中

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

如何在 core java 中将图像保存在 couchbase lite 中?当我们将图像保存在沙发服务器中时,我们将图像转换为字节,然后保存字节。但在 couchbase lite 中却没有这样的功能。请帮助我。

final BufferedImage image = ImageIO.read(new File(file.getPath()));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "png", baos);
Document img_doc = db.getDocument("image");
Map<String, Object> img_properties = new HashMap<String, Object>();
img_properties.put("image", bytes);
img_doc.putProperties(img_properties);

最佳答案

任何无效的 JSON 类型(例如图像)都可以作为二进制附件存储在 Couchbase Lite 中。附件是使用 Revision 对象上的 setAttachment 创建的。附件的内容存储在文件系统中,修订版保留对其的引用。这样,您就可以通过 Document 或 Revision 对象获取附件。请参阅代码示例 here .

关于java - 将图像保存在 couchbase lite java 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30532087/

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