2015-05-29 111 views
0

如何将图像保存在核心java中的couchbase lite中? 当我们将图像保存在couchase服务器中时,我们将图像转换为字节并保存字节。 但它在couchbase lite中没有那样的。 请帮助我。将图像保存在couchbase lite中java

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); 
+0

我将图像转换为字节数组并将其保存到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 img_properties = new HashMap (); img_properties.put(“image”,bytes); img_doc.putProperties(img_properties); –

回答

1

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