2014-06-27 94 views
0

继在RavenDB Attachment docsRavenDB Attachments - Functionality how to do?样品,我试图将附件添加到一个乌鸦的实例与下面的代码:DocumentStore.DatabaseCommands.PutAttachment默默地失败

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只是返回一个空数组。

有一个步骤,我需要采取以保存附件?

回答

0

的问题是,http://localhost:8080/static/?start=0&pagesize=128不显示我的附件。当我找到他们:

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

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

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

2

问题是documentStore.DatabaseCommands会返回一个db命令用于默认的数据库。

你可能需要做的:

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