Objective
Recent projects because to save pictures and files, tossing the ravendb, using RAVENDB FS system Unified management of pictures and files.
Installation
The RavenDB FS file system requires a remote differential compression feature for Windows:
Download the ravendb Zip package after installation.
After unpacking, add the Web folder under directory to IIS:
After the IIS new site is set up, the next step is to set up its corresponding application pool and set the version to 4.0 Integrated mode:
In accordance with the requirements of the official website, it is also necessary to set the disable overlapping collection to true:
Set the Read and write permissions for the RAVENDB storage folder, ravendb the storage folder in Web. config:
The above instructions ravendb stored in the E:\Raven folder
Run
Now that it's done, it runs directly on IIS, but everything starts out hard:
Above the error above, RAVEN.WEB.STARTP and the system startup conflict, in Appseting we want to display the setting that class:
<add key="owin:appstartup" value="Raven.Web.Startup, Raven.web, Version =3.5.4.0, Culture=neutral, publickeytoken=37f41c7f99471593" />
Now that the settings are complete, the following is my Ravendb studio interface, because I have added some files, the interface is not quite consistent with you:
Code upload download File
Everything is ready, now try uploading the file using code, first on NuGet:
According to the official website of the document, Ifilesstore for the specific operation of the portal, and is thread-safe, so it is recommended that an application use a Ifilesstore, the code is as follows:
Public classfilesstoreholder{Private Static ReadOnlyLazy<ifilesstore> store =NewLazy<ifilesstore>(CreateStore); Public StaticIfilesstore Store {Get{returnstore. Value; } } Private StaticIfilesstore CreateStore () {Ifilesstore Fsstore=NewFilesstore () {URL="http://127.0.0.1:8090", Defaultfilesystem="Northwindfs" }. Initialize (); returnFsstore; }}
Then upload the interface for iasyncfilessession, through its method registerupload can upload operation, the specific code is as follows:
Ifilesstore store =Filesstoreholder.store;using(varSession =store. Openasyncsession (Newopenfilessessionoptions () {FileSystem="Northwindfs"}) {session. Registerupload ("window of the world. jpg", File.openread (@"D:\DSCN6900.JPG")); awaitsession. Savechangesasync ();}
The downloaded code passes the method Downloadasync, and its return is stream:
using (Iasyncfilessession session = store.) Openasyncsession ()) { usingawait session. Downloadasync (" window of the world. jpg")) { content. CopyTo (new FileStream ("aaa.jpg", FileMode.Create));} }
Summarize
RAVENDB installation configuration is simple, but there are some pits need to be aware that the use of its API is asynchronous, this in the use of the process also requires a little attention.
RavenDB FS Installation Usage Introduction