We are trying to create a utility where the data is taken from legacy system converted into JSON and put onto sync gateway which is having a couch base bucket connected to it. All well went until its about attachment.
We are using HttpClient of .net and using rest API of sync gateway. The problem is, we are able to put document by converting image in base64 string content. but when we try get call using fiddler the image doesn’t come back. It says Not an image [image/png]. Ad following is the raw data :- HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 26548
Content-Type: image/png;
Etag: "sha1-h6+6oSZDArBAkLPLYHdulQ03XDM="
Server: Couchbase Sync Gateway/1.4
Date: Tue, 02 May 2017 09:46:49 GMT
What I am doing is keeping imagename = docid.fileextension of original file. which works fine when I put it by using fiddler. Content type also looks correct but don’t know where is the issue?
You can use curl to see how to add binary attachments using curl, then you can compare with the request generated from from your .net code.
Assuming you have a JPG file on your local client called attach-test.jpg, and you have a document already stored in a DB in Sync Gateway called doc1 at rev1, the following curl command should add the image as an attachment:
curl -vX PUT http://127.0.0.1:4985/db/doc1/attach-test.jpg?rev=rev=1-cd809becc169215072fd567eebd8b8de --data-binary @attach-test.jpg -H "Content-Type: image/jpg"
Then you should see a response similar to the following if you get the document back:
before SG 1.3.1 (1.3.0), the attachment API with public port works fine.
the same request for SG 1.3.1 and SG 1.4 with public port, it return the following error:
{
"error": "not_found",
"reason": "Document revision is not accessible"
}