【问题标题】:DocumentStore.DatabaseCommands.PutAttachment silently failsDocumentStore.DatabaseCommands.PutAttachment 静默失败
【发布时间】:2014-07-01 02:44:12
【问题描述】:

按照RavenDB Attachment docsRavenDB Attachments - Functionality how to do? 中的示例,我正在尝试使用以下代码将附件添加到Raven 实例:

foreach (var currentDoc in docsToStore) {
  byte[] buff = ReadBytesFromFile(currentDoc.FilePath);
  var attachmentId = "attachedpages/" + attachmentCounter;
  var stream = new MemoryStream(buff);

  documentStore.DatabaseCommands.PutAttachment(attachmentId, null, stream, null);
  currentDoc.Attachments.Add(attachmentId);
  session.Store(currentDoc);  //Add the new document to Raven
}
session.saveChanges();

我查看了调试器以确认 MemoryStream 具有我期望的数据。我还在管理工作室中看到了对 currentDoc 的引用。但是,http://localhost:8080/static/?start=0&pagesize=128 只是返回一个空数组。

我需要采取其他步骤来保存附件吗?

【问题讨论】:

    标签: c# ravendb


    【解决方案1】:

    问题是documentStore.DatabaseCommands 会为 default 数据库返回一个 db 命令。

    您可能需要这样做:

    documentStore.DatabaseCommands.ForDatabase("Mydb").PutAttachment
    

    【讨论】:

      【解决方案2】:

      问题是http://localhost:8080/static/?start=0&pagesize=128 没有显示我的附件。当我寻找它们时:

      documentStore.DatabaseCommands.GetAttachmentHeadersStartingWith("", 0, 128);
      
      documentStore.DatabaseCommands.ForDatabase("Mydb")
          .GetAttachmentHeadersStartingWith("", 0, 128);
      

      然后我看到了我一直试图保存的所有附件。

      【讨论】:

        猜你喜欢
        • 2017-01-10
        • 2018-09-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-04
        • 2017-10-08
        • 2019-07-19
        相关资源
        最近更新 更多