I'm using CouchDB 1.5.1 on Linux. Before trying to implement in libCurl, I'm trying to do this using curl. I want to add a document, then add an attachment (standalone) to that same document in a separate call. I can successfully add a document to CouchDB as follows:
curl -X PUT 'http://admin:secret@localhost:5984/mydb/mydoc'
-H 'Content-Type: application/json' -d '{
"name":"john",
"last":"doe",
"age":"30"
}'
The problem I'm having is adding an attachment after the document is added. If I understand correctly, I have to have the revision of the document to add the attachment. Also, it would seem that anything under '_attachments' must be base64 encoded. The base64 also seems to help with documents containing new lines and carriage returns so I thought about encoding all my docs, both text and binary, in base64. I also realize I could just use the base64 cmd. I've been trying something like the following:
curl -X POST 'http://admin:secret@localhost:5984/mydb/mydoc?rev=3-a0241af37764c0389eb0d3c0a9a6540d'
-H 'Content-Type: application/json' -d '{
"_attachments": {
"testfile.txt": {
"content-type":"text/plain",
"data":"'$(openssl base64 < ./testfile)'"
}
}
}'
Currently, I'm getting lots of the following errors ...error.
curl: (6) Could not resolve host: b3IgaW1wbGVtZW50CiAgICAgdGhlbSB5b3Vyc2VsZi4KCiAgQ1VSTE9QVF9XUklU