【问题标题】:Save image in couchbase lite java在couchbase lite java中保存图像
【发布时间】:2015-05-29 14:23:55
【问题描述】:

如何在核心 java 的 couchbase lite 中保存图像? 当我们在 couchase 服务器中保存图像时,我们将图像转换为字节而不是保存字节。 但它在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);

【问题讨论】:

  • 我将图像转换为字节数组并将其保存到 couchbase lite 文档 final BufferedImage image = ImageIO.read(new File(file.getPath())); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "png", baos);文档 img_doc = db.getDocument("image"); Map img_properties = new HashMap(); img_properties.put(“图像”,字节); img_doc.putProperties(img_properties);

标签: java image save couchbase-lite


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 2017-03-01
    • 1970-01-01
    • 2016-03-19
    • 2016-03-28
    • 1970-01-01
    相关资源
    最近更新 更多