代码之家  ›  专栏  ›  技术社区  ›  Marc Seeger

couchdb+ruby中的独立附件

  •  2
  • Marc Seeger  · 技术社区  · 16 年前

    是否有人成功地使用独立附件api(如果可能的话gziped)从ruby向couchdb发送了独立附件?
    我知道有一些卷曲的例子,但我对伤寒的尝试还没有成功。它通常只会在前几个文档之后停止并等待>1分钟。
    Couchrest似乎不支持它,我看过的其他任何库也不支持它

    编辑:澄清 我不寻找常规的base64编码附件。Couchrest做得很好。

    2 回复  |  直到 16 年前
        1
  •  1
  •   Marc Seeger    16 年前

    和伤寒一起工作

    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”字符串作为gziped独立附件存储到couchdb中。

        2
  •  1
  •   Ludovic Kuty    16 年前

    对于二进制独立附件,我只使用io.read(“/path/to/my/file”)将字符串作为:body赋给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}"))