|
以上说明RavenDB存储在E:\Raven文件夹中
运行
一切按照完毕,现在在IIS就直接运行,但万事开头难:
以上错误的以上,Raven.Web.Startp和系统的Startup冲突了,在appseting中我们要显示的设置那个class:
<add key="owin:AppStartup" value="Raven.Web.Startup, Raven.Web, Version=3.5.4.0, Culture=neutral, PublicKeyToken=37f41c7f99471593" />
现在设置都完毕,以下就是我RavenDB的 studio界面,因为我已经添加了一些文件,界面和各位的不太一致:
代码上传下载文件
一切准备就绪,现在使用代码来上传文件试试,首先在nuget上获取:
根据官网的文档,IFilesStore 为具体操作的入口,而且是线程安全的,所以建议一个应用程序使用一个IFilesStore,代码如下:
public>
{
private static readonly Lazy<IFilesStore> store = new Lazy<IFilesStore>(CreateStore);
public static IFilesStore Store
{
get { return store.Value; }
}
private static IFilesStore CreateStore()
{
IFilesStore fsStore
= new FilesStore()
{
Url
= "http://127.0.0.1:8090",
DefaultFileSystem
= "NorthwindFS"
}.Initialize();
return fsStore;
}
}
然后上传用的接口为IAsyncFilesSession,通过其方法RegisterUpload就可以进行上传操作,具体代码如下:
IFilesStore store = FilesStoreHolder.Store;
using (var session = store.OpenAsyncSession(
new OpenFilesSessionOptions()
{
FileSystem
= "NorthwindFS"
}))
{
session.RegisterUpload(
"世界之窗.jpg", File.OpenRead(@"D:\DSCN6900.JPG"));
await session.SaveChangesAsync();
}
下载的代码通过方法DownloadAsync,其返回是Stream:
using (IAsyncFilesSession session = store.OpenAsyncSession())
{
using (Stream content = await session.DownloadAsync("世界之窗.jpg"))
{
content.CopyTo(
new FileStream("aaa.jpg", FileMode.Create));
}
}
总结
RavenDB的安装配置还算是简单,但还是有些坑需要注意,其api的使用都是异步的,这个在使用过程中也需要稍微注意下。 |
|
|