PouchDB,如何在已有附件的文档中添加新附件?
PouchDB, how to add a new attachment in a doc which already has a attachment?
我有一个带有一些附件的文档,现在我想添加一个新附件,怎么办?
我用db.put()来保存我的文档,但是最后只有新的附件在里面,旧的附件丢失了,我的更新文档代码如下:
function addNewDoc() {
var blob30k = base64toBlob(imgSource30k, 'image/png', 1024);
db.get('my0112doc', function(err, doc) {
if (err) {
return console.log(err);
}
db.put({
_id: 'my0112doc',
_rev: doc._rev,
_attachments: {
'random89.png': {
content_type: 'image/png',
data: blob30k
},
}
}, function(err, response) {
if (err) {
return console.log(err);
}
db.allDocs({
include_docs: true,
attachments: true,
descending: true
}, function(err, doc) {
console.log(doc.rows);
});
});
});
}
这是我第一次在我的文档中保存附件,当我添加一个新的附件时,附件 'myattachment.png' 丢失了。
function saveImage(imgSource30M) {
var t1 = new Date();
var blob = base64toBlob(imgSource30M, 'image/png', 1024);
db.put({
_id: 'my0112doc',
_attachments: {
'myattachment.png': {
content_type: 'image/png',
data: blob
}
}
}, (err, doc) => {
var t2 = new Date();
console.log("save in pouchdb timeoff:", t2.getTime() - t1.getTime());
});
}
您是否尝试过 pouchdb 的 putAttachment 而不是 put
?
我有一个带有一些附件的文档,现在我想添加一个新附件,怎么办? 我用db.put()来保存我的文档,但是最后只有新的附件在里面,旧的附件丢失了,我的更新文档代码如下:
function addNewDoc() {
var blob30k = base64toBlob(imgSource30k, 'image/png', 1024);
db.get('my0112doc', function(err, doc) {
if (err) {
return console.log(err);
}
db.put({
_id: 'my0112doc',
_rev: doc._rev,
_attachments: {
'random89.png': {
content_type: 'image/png',
data: blob30k
},
}
}, function(err, response) {
if (err) {
return console.log(err);
}
db.allDocs({
include_docs: true,
attachments: true,
descending: true
}, function(err, doc) {
console.log(doc.rows);
});
});
});
}
这是我第一次在我的文档中保存附件,当我添加一个新的附件时,附件 'myattachment.png' 丢失了。
function saveImage(imgSource30M) {
var t1 = new Date();
var blob = base64toBlob(imgSource30M, 'image/png', 1024);
db.put({
_id: 'my0112doc',
_attachments: {
'myattachment.png': {
content_type: 'image/png',
data: blob
}
}
}, (err, doc) => {
var t2 = new Date();
console.log("save in pouchdb timeoff:", t2.getTime() - t1.getTime());
});
}
您是否尝试过 pouchdb 的 putAttachment 而不是 put
?