nisarga lolage
nisarga lolage

Reputation: 661

How to store Blob in CouchDB using Java?

I have a blob and want to store it to the Apache CouchDb in java. I get the blob like this

Blob blob1 = blobStore.getBlob(containerName, fileName);

How do I store it in CouchDB?

Upvotes: 2

Views: 1121

Answers (1)

Kerr
Kerr

Reputation: 2812

I don't have a set up to test this out, but looking at the documentation, you want to do something like this:

...
Blob blob = blobStore.getBlob(containerName, fileName);
InputStream is = blob.getPayload.openStream();
String contentType = "image/jpeg"; //or whatever content the blob is.
AttachmentInputStream ais = new AttachmentInputStream("attachment_id", is, contentType);
db.createAttachment("new_document_id", ais);
...

Obviously you would need exception handling and error checking.

Upvotes: 2

Related Questions