我刚刚开始使用 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"
我一直在四处搜索,但只看到了首先创建文档然后添加附件的示例。有没有一种方法可以在一个命令中执行此操作?非常感谢!
最佳答案
如果您传递他们的内容 base64 编码,您可以同时创建/更新文档和设置附件:
curl -X PUT http://localhost:5984/test/docid -d '{"_attachments": {"message.txt": {"data": "aGVsbG8sIENvdWNoIQ==", "content_type": "text/plain"}}}' -H "Content-Type:application/json"
如果文档已经包含一些附件,请不要忘记保留它们的 stub ,否则它们将被删除:
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"
关于database - CouchDB - 一步创建一个带附件的文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16406988/