CouchDB通过命令行动态连接

CouchDB通过命令行动态连接,couchdb,couchbase,couchdb-futon,Couchdb,Couchbase,Couchdb Futon,问题 我希望能够通过命令行(见下文)在创建文档时附加一个/多个附件。我只能在Futon(Couchbase)中使用,但必须在创建文档之后 我尝试了以下方法: curl -X PUT 'http://username:password@localhost:5984/client_info' curl -X POST 'http://username:password@localhost:5984/client_info' -H 'Content-Type: application/json' -

问题

我希望能够通过命令行(见下文)在创建文档时附加一个/多个附件。我只能在Futon(Couchbase)中使用,但必须在创建文档之后

我尝试了以下方法:

curl -X PUT 'http://username:password@localhost:5984/client_info'

curl -X POST 'http://username:password@localhost:5984/client_info' -H 'Content-Type: application/json' -d '{"client_type": "Private", "client_name": "John Doe","client_email": "john@doe.com","client_city": "Toronto","created_at": "2011-09-06 12:45:03","expires_at": "2012-01-01 00:00:00", "_attachments": {
   "test01.jpg": {
       "content_type": "image/jpeg",
       "length": 30189          
    }
  }
}'
这只会导致以下错误:

{"error":"unknown_error","reason":"function_clause"}

谢谢

您必须在单独的步骤中上载附件,在请求正文中包含实际的附件文件。因此,首先创建常规文档,然后在上传文件的地方发出另一个请求。下面是一个关于如何使用curl上传附件的示例(http://guide.couchdb.org/draft/api.html#attachments):
curl-v-X PUT--data binary@artwork.jpg-H“内容类型:image/jpg”


这是附件的官方API:

这是一种在创建文档时以相同请求上传附件的方法

curl -X POST 'http://user:pass@localhost:5984/client_stuff' -H 'Content-Type: application/json' -d '{"stuff": "stuff", "_attachments": {
   "empty.gif": {
       "content_type": "image/gif",
       "data": "'$(openssl base64 < file.gif)'"
    }
  }
}'
curl-X POST'http://user:pass@localhost:5984/client_stuff'-H'内容类型:application/json'-d'{“stuff”:“stuff”,“_附件”:{
“empty.gif”:{
“内容类型”:“图像/gif”,
“数据”:“$(openssl base64
根据您的使用情况,Base64编码可能没有那么糟糕


更多信息:

这对我来说很有效,而且似乎有点简单。如果不添加修订版,则第一个必须在创建文档时进行。我的示例使用数据库“test1”


所以我首先需要创建文档,获得一个_rev,然后使用PUT来最终附加一个图像?为什么不能同时做到这一点?如果我想输入的信息来自注册表,用户可以上传一张或多张图片,该怎么办?我该怎么做呢?如果您正在寻找一种高度可扩展的二进制对象存储,它可以同时写入bucket之类的内容,CouchDB可能不是您的首选。对于您的问题,仍然有几个解决方法:在本地存储已上载图像的本地副本,并将它们排队以进行顺序上载。或者,将每个图像存储在不同的文档中(允许并行上载),并且只在用户文档中添加图像文档的_id。在一个请求中完成所有操作:Base64对图像进行编码并将其包含到文档JSON中(性能方面很差)。如果出现错误:“未找到匹配项:…”将url放入引号:curl-v-X put''--data binary@artwork.jpg-H“内容类型:image/jpg”
$ curl -H "Content-Type: image/jpeg" -X PUT --data-binary @test01.jpg 'http://username:password@localhost:5984/test1/client_info/test01.jpg'

{"ok":true,"id":"client_info","rev":"1-8584b6af9d0c3347ba08202697f09952"}

$ curl -H "Content-Type: image/jpeg" -X PUT --data-binary @test02.jpg 'http://username:password@localhost:5984/test1/client_info/test02.jpg?rev=1-8584b6af9d0c3347ba08202697f09952'

{"ok":true,"id":"client_info","rev":"2-623b94aba30944d6744f5c11cf03fc10"}