Save image in couchbase lite java

how to 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.
kinldy help me.


Hey @zeeshan_niazi,

Would you be able to share some of the code that you already have that isn’t working? I would like to help you troubleshoot, but first want to find out where we stand.


as i was working in couchbase server, so i used the same technique that i was using in couchbase server, i convert image in bytes and than save it in document. like is below:

BufferedImage image = 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);

Hi @zeeshan_niazi,

Following link is for to store/read the attachment from/to database.

I hope this helps you.

the link provided for help contain the following code:
protected void onActivityResult(int requestCode, int resultCode, Intent data){
InputStream stream = null;
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
InputStream stream = getContentResolver().openInputStream(data.getData());
// Add or update an image to a document as a JPEG attachment:
Document doc = database.getDocument(“Robin”);
UnsavedRevision newRev = doc.getCurrentRevision().createRevision();
newRev.setAttachment(“photo.jpg”, “image/jpeg”, stream);;
this code shows an error an able to find getContentResolver()
i searched for jar, that any jar contains this class or method. but unable to find.
kindly help.

Hi @zeeshan_niazi,

I believe that getContentResolver() is Android method. You need to replace this line with your code to obtain InputStream.

Following is our ToDo Lite sample for Android. I believe this snippet also helps you.