2013-05-06 38 views
3

我剛開始使用CouchDB和我已經能夠創建一個文檔,使用兩個步驟的過程附件:CouchDB - 在一個步驟中創建一個帶有附件的文檔?

$ curl -X PUT http://localhost:5984/test/small -H "Content-Type: application/json" -d {} 
$ curl -X PUT http://localhost:5984/test/small/attachment?rev=1-967a00dff5e02add41819138abb3284d --data-binary @small.mp4 -H "Content-Type: video/mp4" 

我一直在四處尋找了一下,我只是完成看到第一次創建文檔並隨後添加附件的示例。有一種方法可以在單個命令中執行此操作嗎?非常感謝!

回答

6

您可以創建/更新文檔,如果你通過他們的內容base64編碼設置附件在同一時間:

curl -X PUT http://localhost:5984/test/docid -d '{"_attachments": {"message.txt": {"data": "aGVsbG8sIENvdWNoIQ==", "content_type": "text/plain"}}}' -H "Content-Type:application/json" 

如果文件已經包含一些附件,不要忘記保持自己的存根否則將被刪除:

curl -X PUT http://localhost:5984/test/docid -d '{"_rev": "1-c5715e943df193437ca89e66982562a5", "_attachments": {"another_message.txt": {"data": "UmVsYXgh", "content_type": "text/plain"}, "message.txt":{"content_type":"text/plain","revpos":1,"digest":"md5-G8EmVzBQlBaB8+bLeMMzeg==","length":13,"stub":true}}}' -H "Content-Type:application/json" 
相關問題