2010-04-20 44 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}"))