XEdwin / jcouchdb

Automatically exported from code.google.com/p/jcouchdb
Other
0 stars 0 forks source link

Attachment's getData returns null #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Here is the program I am running
Database ipsDatabase = new Database("localhost", 5984, "test");
ViewResult<Map> allDocs = ipsDatabase.listDocuments(new Options(), new
JSONParser());
List<ValueRow<Map>> pAllDocs = allDocs.getRows();
Attachment data;

for (ValueRow<Map> doc: pAllDocs) {
   System.out.println("----------------");
   System.out.println("ID = " + doc.getId());
   BaseDocument d = ipsDatabase.getDocument(BaseDocument.class, doc.getId());
   data = d.getAttachments().get("ips");
   System.out.println("Length = " + data.getLength());
   System.out.println("Content-Type = " + data.getContentType());
   System.out.println("Data = " + data.getData());
}

and here is the output

----------------
ID = 5802341721811236
Length = 709
Content-Type = application/octet-stream
Data = null
----------------
ID = 5828961721221236
Length = 47
Content-Type = application/octet-stream
Data = null
----------------

I can confirm that the length and type is correct, but there is data in the
attachment.

Thanks

Original issue reported on code.google.com by adakkak@gmail.com on 5 Mar 2009 at 5:00

GoogleCodeExporter commented 9 years ago
jcouchdb mirrors the way couchdb itself works. the _attachments object is only 
filled
with data for creating attachments inlined. filling it with data on reads would
require jcouchdb to make additional calls hidden in getDocument, something I am
violently opposed to.

Original comment by ff...@gmx.de on 5 Mar 2009 at 9:42

GoogleCodeExporter commented 9 years ago
while I figured it out, using:

BaseDocument d = ipsDatabase.getDocument(BaseDocument.class, doc.getId());
data = ipsDatabase.getAttachment(doc.getId(), "ips");

can you remove or hide the getData() ?

Original comment by adakkak@gmail.com on 5 Mar 2009 at 9:51

GoogleCodeExporter commented 9 years ago
I don't think that would be a good idea. it would just ruin all symmetry and
simplicity and add very little.

I added some more documentation about this issue. 

Original comment by ff...@gmx.de on 6 Mar 2009 at 3:35

GoogleCodeExporter commented 9 years ago
How can I assign a id value to attachment just like the "ips" above?
Where is the documentation about it ?

Original comment by liujiawi...@gmail.com on 25 Oct 2013 at 2:42