I am using Ektorp (Java API for CouchDB) to store documents in my CouchDB instance. I am having trouble attaching images to documents. Every time I call createAttachment()
it throws an ClientProtocolException
.
Code Sample:
AttachmentInputStream attachment =
new AttachmentInputStream(attachmentId,
fileInputStream,
contentType,
file.length());
String rev = db.createAttachment(doc.getId(), attachment));
Does anyone know what's going wrong?
I had a similar problem using Ektorp. I resolved the issue by passing the latest revision number into the overloaded createAttachment method (db.createAttachment(doc.getId(), doc.getRevision(), attachment))). You could probably do the following:
AttachmentInputStream attachment =
new AttachmentInputStream(attachmentId,
fileInputStream,
contentType,
file.length());
String rev = db.createAttachment(doc.getId(), doc.getRevision(), attachment));
Good luck!