Skip to content

Instantly share code, notes, and snippets.

@ZavenArra
Created May 31, 2012 22:24
Show Gist options
  • Save ZavenArra/2846740 to your computer and use it in GitHub Desktop.
Save ZavenArra/2846740 to your computer and use it in GitHub Desktop.
Creating attachment creates 2 documents
Original doc. Notice _rev is on #3 which is because it has been created, then had 2 attachments added.
{"_id":"2e4a9635-c225-47c8-84d9-3f9c42d81970","_rev":"3-37aa4534-dd09-49b2-952b-7cc809c6f904","created_at":"2012-05-31T22:18:12.835+0000","longitude":"-122.29621807","deviceuser_identifier":"ANDROID00000000-6ecb-bb13-fc46-a7570033c587","latitude":"37.80973901","_attachments":{"medium.jpg":{"content_type":"image/jpeg","revpos":3,"length":65,"stub":true},"thumb.jpg":{"content_type":"image/jpeg","revpos":2,"length":64,"stub":true}}}
This is the 2nd mystery document, which has an id which looks suspiciously like a revision number.
{"_id":"2-83c6f8cf-1a3b-4dfd-8d5f-bebe618c01f5","_rev":"1-41670c94-c5b7-4fa8-a69f-418548cb60c9","_attachments":{"thumb.jpg":{"content_type":"image/jpeg","revpos":1,"length":64,"stub":true}}}
Again for reference the code that creates this document
String id = documentNode.get("_id").getTextValue();
byte[] thumb = values.getAsByteArray("thumb");
//byte[] thumb = new byte[] {'a','b'};
ByteArrayInputStream thumbStream = new ByteArrayInputStream(thumb);
AttachmentInputStream a = new AttachmentInputStream("thumb.jpg",
thumbStream,
"image/jpeg");
String _rev =couchDbConnector.createAttachment(id, documentNode.get("_rev").getTextValue(), a);
couchDbConnector.createAttachment(_rev, a);
byte[] medium = values.getAsByteArray("medium");
int ln = medium.length;
a = new AttachmentInputStream("medium.jpg",
new ByteArrayInputStream(values.getAsByteArray("medium")),
"image/jpeg");
couchDbConnector.createAttachment(id, _rev, a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment