Azure - Reading and Writing with LocalStorage
Posted
11. prosinac 2008. 15:45
by
dadamec
In a post Azure Storage Services vs SQL Services I mentioned that we could think of Azure Storage as this is File System for us. After that came the usual question: is there any access to File System from Web Role deployed into Azure environment. Well - there is - usage is simple thru the ILocalResource inteface.
It had to be LocalStorage element (WebRole element child) in Service Definition File ServiceDefinition.csdef.
<
LocalStorage name="AIResizerStorage" sizeInMB="2"/>
And this declared local storage is accessible thru the ILocalResource:
ILocalResource myIO = RoleManager.GetLocalResource("AIResizerStorage");
After the initialization you could use the free space in your storage like you use to:
string PathToFile = Path.Combine(resource.RootPath, "myFileInCloud.txt");
FileStream stream = File.Open(PathToFile , FileMode.Create, FileAccess.ReadWrite);
But be carefull!!! This is non-persisted storage - it exists only while WebRole is up and running. Every suspend or restart of the role will clean the local storage. So this is really a temporary storage and we should have this in mind. It is usefull for caching some data, temporary serialization on IO or upload in chunks for example but for the persisted storage we should stick to Storage Tables or Blobs.