0

我正在尝试向现有文档添加附件。我正在使用nano库发送数据和附件,以便以后通过 CBLite 访问。

我创建的那些文件db.attachment.insert似乎很好。但是,现在我需要为每个文档添加多个附件,我遇到了 409 问题。具体来说,我得到:

409

文件存在

我已确认正在发送当前版本。

  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');

```

4

1 回答 1

1

我发现了问题:filename字符串包含#字符,因此导致问题,更改名称/删除有问题的字符似乎已经解决了问题。

于 2017-09-13T13:00:16.653 回答