2014-06-27 133 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