Offline nesting in CouchDB + Ruby
Has anyone succeeded in sending offline attachments using the offline app API (gziped if possible) on couchDB from ruby?
I know there are several CURL examples, but my attempts with Typhoeus have failed so far. It usually just stops and waits> 1 minute after the first few documents.
CouchRest doesn't seem to support it, none of the other libraries I've looked at
Edit: Clarification I'm NOT looking for Base64 encoded regular attachments. CouchRest does this pretty well.
a source to share
Got a job with typhoid
Typhoeus::Request.put("http://127.0.0.1:5984/db/document/my_attachment_name?rev=#{rev}", "content-type" => "text/html", "Content-Encoding" => "gzip", "Accept-Encoding" => "gzip", :body => my_html_body)
this will save the string "my_html_body" in couchDB as a standalone gziped attachment
a source to share
For binary offline nesting, I just used IO.read ("/ path / to / my / file") to give the string to the put method as body :. It looks like it works, but I don't know if it's the right way to do it.
It looks like this:
res = Typhoeus::Request.get("http://localhost:5984/_uuids")
uuid = JSON.parse(res.body)["uuids"].first
doc = {}
doc["name"] = name
...
res = Typhoeus::Request.put("http://localhost:5984/products/#{uuid}", :body => JSON.generate(doc))
res = Typhoeus::Request.put("http://localhost:5984/products/#{uuid}/image.jpg?rev=#{rev}", :headers => {"Content-Type" => "image/jpeg" }, :body => IO.read("output/images/#{image}"))
a source to share