We’re building an application which allows users to fill in a form on a mobile app, allowing photo’s to be attached.
These forms are viewable and editable from a web application which used direct queries to Couchbase Server. Is it possible to create multiple attachments direct using the couch base server SDKs or N1QL queries?
The current method I found that would work has quite a cumbersome procedure:
- Multiple requests come in from the web app to an API (to ensure the requests aren’t too large with multiple attachments)
- Retrieve latest revision of the document using a request to the Sync Gateway (_raw endpoint, as described in https://blog.couchbase.com/shared-access-couchbase-database-web-mobile-apps/)
- Send request to Sync gateway to create new attachment for document, including received revision property
This method has not been tested and does not sound too complicated, however, I can see multiple issues:
In step 2 and 3, when 2 requests are executing at the same time, they might retrieve the same revision property which they use to create a new attachment, causing an error due to the revision already existing.
I can chain up the request, so 1 waits for the previous one to finish, but this process is not really optimal.
I read a Sync Gateway 2.0 version is coming soon, does this have any changes/improvements to the attachment system, if so, we’ll leave this part for now and wait for the new version to become available.