Save image attachment

The problem was that posing binary data as attachments, rather than json documents. It’s ok for now though, I’ve written some native plugins for react-native-couchbase-lite that handle the binary upload.

Hi,

I’m using the format you mentioned to upload a png as attachment on a already inserted document.

curl -X PUT --header Content-Type: image/png --data-binary @workflow.png http://x:x:x:x:4984/db/Inspection_1/workflow.png?rev=7-14d758c9a18800000000000000000000

However, I got the following response.

{“error”:“conflict”,“reason”:“Document revision conflict”}

I’m using the revision id which is listed near to document in the web ui. What is wrong in my request? From mobile side, attachment can be added smoothly but we need to add from server app as well. (My cb server version is 5.0)

Thanks.

It sounds like you get this error with Sync Gateway, not Couchbase Lite? Which version? (The CB server version doesn’t really matter.)

I’m using the revision id which is listed near to document in the web ui.

It’s easier and more reliable to just GET the document from the SG REST API (GET http://x:x:x:x:4984/db/Inspection_1) and look at the _rev property. Try that and make sure you’re using the correct revision ID.

If it still doesn’t work, this sounds like a glitch in SG’s implementation of the REST API; file an issue on Github. The workaround would be to update the document, not the attachment itself; the API docs should describe how to do this.

1 Like

Like you said, after getting the revision id by using get request, I got a totally different id. Then when I check it with that id, I was able to overcome the conflict error.

It is very strange that the revision id on the couchbase server and actual revision id are different than the other. It might misguide other people as well.

Anyway, thank you for your support.