Rodrigo Mansho wrote:
I'm using jcouchdb, and Yes, I created a document.
I can store any document, but only text document is correctly opened.
Server server = new ServerImpl(COUCHDB_HOST, COUCHDB_PORT);
server.createDatabase("jcouchdb_test");
FooDocument fooDocument = new FooDocument("document image");
Reader fu = new Reader("pt.gif");
byte [] byteArray = fu.getBytes();
fooDocument.addAttachment("testiagem", new Attachment("image/gif",
byteArray));
Database db = createDatabaseForTest();
db.createDocument(fooDocument);
You can't read attachments the same way they are created. The code above
converts your byte array into a base64 encoded string internally and
creates the documents with that.
But when you request the document, you will only get the meta
information about the attachment: name, mime-type and a boolean flag
called "stub" that signals that the attachment is not fully included
in the document.
to read the binary attachment data, you'd have to call
database.getAttachment( fooDocument.getId(), "testiagem");
with the two arguments being the document id and the attachement id.
This will internally do a GET from
http://server:5984/database_name/doc_id/attachment_id
This is just the way attachments work in CouchDB and should most likely
be better explained in the jcouchdb documentation.
Regards,
Sven Helmberger