0

How do I save image in couchbase lite in core java? As we save image in couchase server, we convert image to bytes and than save bytes. But its not having like that in couchbase lite. Kindly help me.

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);
jev
  • 2,023
  • 1
  • 17
  • 26
Waqas
  • 49
  • 4
  • I convert the image into byte array and save it to couchbase lite document 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); – Waqas May 29 '15 at 14:40

1 Answers1

1

Any non-valid JSON type (like an image for example) can be stored in Couchbase Lite as a binary attachment. The attachment is created using the setAttachment on the Revision object. The content of the attachment is stored in the filesystem and the revision keeps a reference to it. That way, you can get the attachment through the Document or Revision object. See the code example here.

jamiltz
  • 1,144
  • 8
  • 15