couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sven Helmberger <sven.helmber...@gmx.de>
Subject Re: Developing CouchDB in JAVA
Date Fri, 30 Jan 2009 14:50:30 GMT
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

Mime
View raw message