CouchDB通过命令行实时附件

Edv*_*rdG 8 couchdb couchdb-futon couchbase

问题

我希望能够通过命令行(见下文)在创建文档时附加一个/多个附件.我只能在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          
    }
  }
}'
Run Code Online (Sandbox Code Playgroud)

这只会导致以下错误:

{"error":"unknown_error","reason":"function_clause"}
Run Code Online (Sandbox Code Playgroud)

谢谢

b_e*_*erb 16

您必须在单独的步骤中上传附件,其中包含请求正文中的实际附件文件.因此,首先创建常规文档,然后在上载文件的位置发出另一个请求.以下是有关如何使用curl上传附件的示例(http://guide.couchdb.org/draft/api.html#attachments):curl -v -X PUT http://127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af/artwork.jpg?rev=2-2739352689 --data-binary @artwork.jpg -H "Content-Type: image/jpg"

以下是附件的官方API:http://wiki.apache.org/couchdb/HTTP_Document_API#Standalone_Attachments


Jus*_*ing 5

这对我有用,看起来有点简单.第一个必须是在创建文档时,如果你不添加转速.我的例子使用数据库"test1".

$ 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"}
Run Code Online (Sandbox Code Playgroud)