Re: attachments not being replicated from touchdb to couchdb.

287 views
Skip to first unread message

Mohit

unread,
Oct 25, 2012, 7:04:10 PM10/25/12
to mobile-c...@googlegroups.com
update: I tried the touchdb testapp, and the unit tests for attachments and attachments-using-ektorp both pass.

(tests: https://github.com/couchbaselabs/TouchDB-Android/blob/master/TouchDB-Android-TestApp/src/com/couchbase/touchdb/testapp/tests/Attachments.java, and
https://github.com/couchbaselabs/TouchDB-Android/blob/master/TouchDB-Android-TestApp/src/com/couchbase/touchdb/testapp/ektorp/tests/Attachments.java)

But these tests seem to cover adding and retrieving attachments from a local database only...I am able to attach images to couchdb documents using futon,
so I'm assuming the problem might be with either ektorp or touchdb's attachment/replication api implementation.
Or with my implementation above :-)

Please let me know if you have any thoughts on this!

Marty Schoch

unread,
Oct 25, 2012, 7:16:48 PM10/25/12
to mobile-c...@googlegroups.com
I'm pretty sure the problem is not in Ektorp, it is in the replicator
implementation. The TouchDB-Android replicator is a mess and I
haven't any time to work on it for about 2 months now.

marty

Marty Schoch

unread,
Dec 3, 2012, 11:58:27 AM12/3/12
to mobile-c...@googlegroups.com
I haven't yet gone back to working on TouchDB-Android, but I hope to this week.  First up will be merging the replicator fixes branch to mainline (no one reported it being worse than the main branch, and I feel it is better).

Next will be seeing why attachments aren't getting pushed.

What I can say is that if your attachments look correct in TouchDB (which seems to be what you're saying), then there is no need to review the code that creates the attachment.  The problem must be in the replicator.

marty


On Mon, Dec 3, 2012 at 6:57 AM, Bart <bart....@gmail.com> wrote:
Hi Marty,

Did you make any progress yet on the TouchDB-Android replicator? I seem to be having a similar problem when creating attachments. I am trying to add an attachment to an existing document using the following piece of code:

        final File attachmentFile = new File(URI.create(uri.toString()));
        final String contentType = "image/jpeg";
        final AttachmentInputStream attachmentContents = new AttachmentInputStream(attachmentFile.getName(), new FileInputStream(attachmentFile), contentType);
        couchDbConnector.createAttachment(resourceId, revision, attachmentContents);

Note that uri points to a valid file, and both resourceId and revision are also correct.

I'm not getting any errors in the log but after replicating to the central CouchDB, the document has no attachments whatsoever. Even worse: any existing attachments seem to have been removed from the document as well.
The local version of the document does seem to have the attachment attached correctly.

Kind regards,

Bart

--
 
 

Jens Alfke

unread,
Dec 12, 2012, 1:01:39 PM12/12/12
to mobile-c...@googlegroups.com

On Dec 12, 2012, at 12:00 AM, Paschal Maduhu <maduh...@gmail.com> wrote:

is there any progress on the TouchDB attachments Replication.

Looking at the commit history of the repo is a good way to answer questions like that. 
Marty has said several times recently that he hasn’t had time to work on TouchDB in recent months, but plans to start again soon.

—Jens

Okan Ozturk

unread,
Dec 4, 2013, 8:12:46 AM12/4/13
to mobile-c...@googlegroups.com
i have same issue, is there any progress on that ?

25 Ekim 2012 Perşembe 13:04:38 UTC+3 tarihinde Mohit yazdı:
Hi all, 

quick question: do attachments get replicated across touchdb and couchdbs? 

(I saw prior posts with problems regarding this, e.g. https://groups.google.com/forum/#!topic/mobile-couchbase/h_7sAddedvw)

When I add an image attachment to a document on the touchdb client -- following which I can get the attachment and display it locally -- the attachment does not show up on the couchdb server. To check, I can see the local document size go from 100kB to 600kB when I add a photo, but the remote document size only increases from 20kB to 33kB. (curl -X GET ../_all_docs output below).

Other android clients replicating with couchdb crash when trying to get the attachment from their local touchdb. The document name, however gets replicated correctly, which indicates that replication (minus the attachments) seems to work fine across touchdb and couchdb.

Let me know if you have any suggestions! Thanks,
Mohit

Setup: Touchdb-android(JB)-client replicating push and pull with Couchdb 1.2.0

Code for creating attachment on touchdb client:
public void insertPhoto(Photos photo) {
String imagePath = photo.getUri();
File file = new File(imagePath);
InputStream data = null;
try {
data = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String contentType = "image/jpeg";

AttachmentInputStream a = new AttachmentInputStream(new String(photo.getTimeStamp()),
data, contentType);

lastInsertedId = dbInterface.createAttachment(new String(photo.getTimeStamp()), a);  // calls dbConnector.createAttachment(string, a);
}

_all_docs on touchdb: curl -X GET touchdb-android:5984/photoapp/_all_docs

{"offset":0,"total_rows":2,"rows":[{"value":{"rev":"1-9b6b0dc3-2220-4789-a2a5-d4a311b1727b"},"id":"IMG_20121025_024511.jpg","key":"IMG_20121025_024511.jpg"},{"value":{"rev":"1-2ac6632b-8aca-453c-a955-7546d560fc68"},"id":"IMG_20121025_024633.jpg","key":"IMG_20121025_024633.jpg"}]}


_all_docs on couchdb:  curl -X GET server:5984/photoapp/_all_docs

{"total_rows":2,"offset":0,"rows":[
{"id":"IMG_20121025_024511.jpg","key":"IMG_20121025_024511.jpg","value":{"rev":"1-9b6b0dc3-2220-4789-a2a5-d4a311b1727b"}},
{"id":"IMG_20121025_024633.jpg","key":"IMG_20121025_024633.jpg","value":{"rev":"1-2ac6632b-8aca-453c-a955-7546d560fc68"}}
]}

Jens Alfke

unread,
Dec 4, 2013, 10:19:49 AM12/4/13
to mobile-c...@googlegroups.com

On Dec 4, 2013, at 5:12 AM, Okan Ozturk <ozz...@gmail.com> wrote:

i have same issue, is there any progress on that ?
 
That thread is a year old. A lot changes in a year. It’s better to start a new thread than to wake up an old one.

If you’re having a problem, please describe the details, including exactly what software you’re using. (If you really are trying to use TouchDB for Android, that’s a very old and incomplete version of the software; please upgrade to Couchbase Lite instead.)

—Jens
Reply all
Reply to author
Forward
0 new messages