ouchDB更新附件 [英] couchDB update attachments

查看:54
本文介绍了ouchDB更新附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以更新现有文档的附件而无需再次上传吗?

Can I update the attachments of an existing document without uploading them again?

我尝试过:

<?php
    $json = '
    {
        "_id":"attachment_doc",
        "_rev":'.$rev.',
        "_attachments":
        {
            "free-wallpaper-31.jpg":
            {
                "revpos":3,
                "content_type":"image\/jpeg",
                "data": "'.base64_encode(file_get_contents('free-wallpaper-31.jpg')).'"
            }
        }
    }
';

$doc = $couchdb->doc_upload_attachments('16beb67b990604791b3ffde7dd000576', $json);
var_dump($doc);
?>

但这会覆盖现有的附件,并以新的修订版本存储文档。

But that overwrites the existing attachments and stores the document with a new revision.

推荐答案

我对PHP的API并不熟悉,但是通常在CouchDB REST API中,您可以上传附件而无需上传文档和其他先前上传的附件。看一下《定性指南》中 API章节的附件部分。在命令行中:

I am not familiar with the API for PHP, but in general in CouchDB REST API you can upload an attachment without uploading the document and other previously uploaded attachments. Take a look at attachment section of API chapter in The Definite Guide. In command line:

curl -vX PUT http://localhost:5984/YOUR_DB/YOUR_DOCUMENT/YOUR_ATTACHMENT.jpg?rev=REVISION_OF_THE_DOCUMENT_BEFORE_UPLOADING_AN_ATTACHMENT --data-binary @FILE_ON_THE_DISK.JPG -H "Content-Type: image/jpg"

它对我有用:)是的,上传成功后必须更改文档的修订版。如果您在使用语言绑定时上载时遇到问题,只需使用标准HTTP API上载即可。

It works for me :) And yes, the revision of the document has to change when uploading succeeds. If you have trouble uploading with the bindings in your language, just upload it with standard HTTP API.

这篇关于ouchDB更新附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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