2010-04-20 43 views
2

有沒有人成功地使用獨立附件API(如果可能的話)發送獨立附件到ruby的couchDB?
我知道有幾個CURL的例子,但我的嘗試與Typhoeus迄今尚未成功。它通常停止並在頭幾個文件後等待> 1分鐘。
CouchRest似乎不支持的話,也不做任何我已經看了CouchDB + Ruby中的獨立附件

編輯其他庫:澄清 我不是找正規Base64編碼的附件。 CouchRest做得很好。

回答

1

得到它與百頭巨怪

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) 

這將在「my_html_body」串入的CouchDB存儲爲gziped獨立附件

1

對於二進制附件獨立,我只是用IO.read(「工作/路徑/到/我的/文件「)給put方法的字符串作爲:主體。它看起來像在工作,但我不知道這是否是正確的方式。

它看起來像這樣:

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}"))