I am trying to add an attachment to an existing document. I am using the nano library to send the data and attachments, for later access via CBLite.
Those documents I created from the db.attachment.insert
seem to be fine. However, now I need to add multiple attachments per doc, I am running into the 409 issue. Specifically I am getting:
409
Document exists
I've confirmed that the current revision is being sent.
try {
let response = await db.getAsync(docId);
rev = response._rev;
console.log ('existing entry, rev:' + rev);
} catch (error) {
console.log ('new entry');
let docRes = await db.insertAsync(word, docId);
console.log (docRes);
rev = docRes.rev;
}
//...
var data = {};
try {
data = await fs.readFile(filePath);
} catch (ex) {
console.log ("error: "+filePath);
console.log (ex);
continue;
}
if (data) {
try {
console.log ('inserting '+filename+' at rev', rev);
let res = await db.attachment.insertAsync(docId, filename, data, 'audio/mpeg', {rev: rev});
console.log('attachment inserted', res);
} catch (error) {
console.log (error.statusCode);
console.log (error.message);
}
} else console.log('file data empty');
```
I found the problem: the filename
string contained #
characters and so was causing problems, changing the name/removing the offending characters seems to have solved the issue.