How to put attachments into a bucket using the Node.js API?

Hello experts,

I’m trying to transfer some image files of thumbnails (one per CB document) to the iOS app that I’m writing.

I’m entering documents into my main bucket using the Node.js API, and the data gets synced to the iOS devices using the CB Sync Gateway and CBL.

I’ve seen that there are ways to add attachments to CB documents, or to save binary data as Base64-encoded strings.

I couldn’t find anything in the Node.js API that suggested that attachments are supported, so please give me some pointers.

What would be the best way to transfer small files to the iOS devices?

I’ve seen that Connection.set(…) can take a value of type Buffer. Would that help me to achieve my goal?

Cheers,
Florian

__
I’ve posted a similar question before but it wasn’t answered… that’s why I’m posting this in the hope that the slight rephrasing helps it getting an answer.

I think what you are looking for is actually something like this. Basically this code stores an image captured in the browser and stores it in Couchbase. Works pretty nicely!

The Bucket.add function seems to have been removed in the current version of couchnode. Is there anyway in the new version of couchnode to add/update attachments? I checked the API here and I couldn’t find any reference to attachments: http://docs.couchbase.com/sdk-api/couchbase-node-client-2.0.2/Bucket.html

Still think this is an issue. Decoding base64 is an pain in the ass. It’s ultra slow and I want to share image data that is processed by Couchnode with mobile devices. Isn’t there a proper way to do this? Like this but then for Nodejs:

CBLDocument* doc = [db documentWithID: @"Robin"]; CBLRevision* rev = doc.currentRevision; CBLAttachment* att = [rev attachmentNamed: @"photo.jpg"]; UIImage* photo = nil; if (att != nil) { NSData* imageData = att.content; photo = [[UIImage alloc] initWithData: imageData]; }

Or if there’s an example online without the base64 decoding? Right now I’m doing this to make image loading more efficient. And it sucks:

  • Create base64 image on nodeJS
  • send to mobile device.
  • decode on device
  • send back to couchbase

Hi, what’s the status? I also looking for a way to upload assets in couchnode.