CouchDB - 一步创建带附件的文档? [英] CouchDB - Create a document with an attachment in one step?

查看:143
本文介绍了CouchDB - 一步创建带附件的文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用CouchDB,并且我已经能够使用两步流程创建带附件的文档:

I'm just starting out with CouchDB and I've been able to create a document with an attachment using the two step process:

$ 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"

我一直在搜索一下,我只看到了首次创建文档并随后添加附件的示例。有没有办法可以在一个命令中执行此操作?非常感谢!

I've been searching around for a bit and I've only seen examples where the document is first created and the attachment is subsequently added. Is there a way I can do this in a single command? Thank you much!

推荐答案

如果您传递内容base64编码,您可以同时创建/更新文档并设置附件:

You can create/update document and set attachments in same time if you pass their content base64-encoded:

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

如果文档已经包含一些附件,请不要忘记保留它们的存根,否则它们将被删除:

If document already contains some attachments, don't forget to keep their stubs or they will be removed:

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"

这篇关于CouchDB - 一步创建带附件的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆