0

如何在核心 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);
4

1 回答 1

1

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

于 2015-06-16T19:14:04.153 回答