Synchronise blobs using SyncGateway

Hi all,

I am currently using the Couchbase Mobile solution to synchronize data from my Couchbase Server to my local computer.
I have no problem to synchronize my JSON documents from my Couchbase Server to my local device, however, the binary documents are never synchronized. It seems that the problem I have encoutered concerns about the Blob documents.
I read about storing blobs using Attachments, as it is specified here : http://developer.couchbase.com/mobile/develop/guides/couchbase-lite/native-api/attachment/index.html
The thing is that I can’t pull blobs from my server using the Sync Gateway.

I am using Couchbase Lite 1.0.4 (The Java library) and here is some of my project to synchronize my data using Sync Gateway :

Database db = null;
	try {
	  final Manager manager = new Manager(new JavaContext("data"), Manager.DEFAULT_OPTIONS);
	  db = manager.getDatabase("myDatabase");
	  db.open();
	  
	  final URL url = new URL("http://127.0.0.1:4984/myDatabase");
	  final Replication pull = db.createPullReplication(url);
	  pull.start();
	  
	  ...

I have tried many things such as adding parameter to the Replication object (ChangeListener, CountDownLatch)… no success.

I have no error message either on my Sync Gateway console or my Eclipse console. But none of my blob is synchronized to my Couchbase Lite.

The questions is as follows : Is it possible to pull binary documents from the server to Couchbase Lite using Sync Gateway?

Thank you.

nico34

Hi,

You should be able to pull attachments from Sync gateway.
Do you get the document but not the attachment? Can you sync doc without attachments?

Thanks

Hi Idoguin,

I am not able to pull any attachment from Sync Gateway,
I can get all the JSON documents, but none attachment. It’s like my Sync Gateway ignore all my binary documents.

Thank you,

@nico34

If you run the following curl command:

curl -X GET http://127.0.0.1:4984/myDatabase/mydocwithattachments

Do you see the _attachment metadata in the JSON document that is returned?

You can retrieve a single attachment with the following curl

curl -X GET http://127.0.0.1:4984/myDatabase/mydocwithattachments/attachmentname

You can get the document with all the attachments inlined in base64 with the following curl

curl -X GET http://127.0.0.1:4984/myDatabase/mydocwithattachments?attachments=true

Let us know if one or more of these calls fails for you, with the response you get from SG.

Andy

Hi @nico34,

I would look into upgrading with the 1.1 release of Couchbase Mobile first.
A good test is to check if you can load the attachment in the browser.
Also, this tutorial might help, it’s loading images from the Places API to SG and then in a Recycler View.

James

Hi @andy,

When you say “mydocwithattachments”, what am I supposed to specify exactly? As you know, in Couchbase Server, we do not have attachments but either JSON documents or Binary documents. There is not necessarily a link between a JSON doc and a Binary document. How a binary document could be associated to a JSON one.
So “mydocwithattachments” is a Binary document ID (of CouchbaseServer)?

@jamiltz, I would say the same thing, what attachment am I supposed to put in the GET request? And about the tutorial, I am not working on an Android project, but I checked the Java code lines about the pull replication, it’s quite the same things that I have.

Thank you both.

@andy I tried the GET http://127.0.0.1:4984/myDatabase/mydocwithattachments
using a binary document ID from Couchbase Server, and the result is :
{
“error”: “not_found”,
“reason”: “missing”
}

I waited for the SG views to finish (_design/sync_gateway, and _design/sync_housekeeping).

However, when I use a JSON Document ID, I can get it ! The answer is the JSON Document :

{
“_id”: “0000e8054dbb4a2a8be42f4155b33c86”,
“current”: {
“hashSelf”: “XXXXXXXXXXXXXXXXXXX”,
“name”: “nico”,
“age”: “15”, …
}

@nico34

I had incorrectly assumed that you had stored the binary/blobs as attachments to JSON document and pushed them to sync gateway through the REST API, as per the link you posted.

Using attachments is the correct way to store and retrieve binary data via Sync Gateway.

If you are storing simple key/value data directly in Couchbase Server, Sync Gateway will not see these and there is no way to request them via the Sync Gateway REST API.

Andy

@Andy Exactly, I have directly store blobs in Couchbase Server. I don’t think there is a way to store binary data as JSON attachment in Couchbase Server isn’t it ? I have looked for it but it seems that we can only store binary data as I’ve done and like it’s explained here : http://docs.couchbase.com/developer/java-2.1/documents-basics.html

I am actually making the link myself in my JSON documents, by adding a field containing a blob ID.

Thank you again.