I’m in the process of migrating an existing solution into Couchbase. In the solution I have some “Photo” entities with scaled down photos (approx. 50-200KB) and I want to sync them to the mobile devices. To ensure transparency and avoid some issues people have been writing about (though these may be old/solved) I decided to Base64 encode the images and just save them as text. Actually, I did a similar thing for Dates (ie. ISO format as text).
However, as I’m now working on the mobile side I have become uncertain whether this is really needed. I have seen in several places that there are special handling for exactly blobs/attachments and Dates.
So I have been trying to find examples of how to simply save a binary file on my JsonDocument in Java on the server side - and haven’t really been able to - apart from a 2 year old example of how to split attachments into several documents. But I really just want to add two (the photo and a thumbnail) to my JsonDocument. Can I do that? And should I prefer that to Base64 encoding it? And if so, how can I do it?
I cannot find a method to save an attachment nor a date… I can only do a
JsonDocument doc = JsonDocument.create("id1" JsonObject.empty()); doc.content().put("photo",imageObj); doc.content().put("date",dateTimeObj);
but then how do I read these again? There seem to be no methods to read a Date object nor a binary image object?
I seem to be able to read a Date and Blob object directly from a record in my ResultSet from a query:
I have not yet looked into saving the same type of information from the mobile side - but finding these methods in C# made me consider if I was doing this incorrectly. There really is no reason to convert back and forth manually if it is not needed
I’m using Java SDK 2.7.1 on my server (and C# SDK 2.1.2 on the mobile side). The server is Community Edition 6.0 and Sync Gateway 2.1.1