Couchbase Lite iOS Bad Data Encoding Error

I’m using Couchbase Lite on a mobile ionic framework project. I create a photo from the device camera in a base64 data URL. I put that into a document _attachments property and it works great on Android when I PUT the doc into CouchBase, but gives a Bad Data Encoding error on iOS.

doc is a JSON object.
                    doc._attachments = {
                        "inPhoto" : {
                            content_type : "image/jpeg",
                            data : imageData // base64 encoded jpeg image from device camera shot.
                        }
                    }
           
                query = encodeURI(COUCHBASEURL + dbName + SLASH + docId + '?rev=' + doc._rev);
                $http.put(query, doc).success(function(data, status, headers, config) {
                    success(data, status, headers, config);
                }).error(function(data, status, headers, config) {
                    fail(data, status, headers, config);
                });

Hits the fail() line with the error: BAD DATA ENCODING

Anyone else seen this or know what might be going on?

I assume you’re using the REST API of Couchbase Lite 1.4? This version is pretty old and won’t be supported much longer, but 2.x doesn’t have a REST API.

It’s possible the iOS implementation didn’t support the data property of an attachment in a PUT. The more usual ways of saving a doc with an attachment are

  • PUT the doc first without the attachment, then PUT the attachment to /dbname/docid/attachmentname as raw data (not base64) using the desired Content-Type.
  • Put the document and attachment in multipart/related form, but this is quite a bit more complicated (see the docs).

Also, I don’t recognize the error message “BAD DATA ENCODING” — that may not be directly from CBL. Can you get the exact HTTP status and response message?