Monday, July 6, 2009

Windows Azure local file storage

When you want to modify a blob in windows azure storage, you may need to download it, modify it, then upload it, it may cost a lot of bandwidth and time. Windows azure platform provides "infinite" storage space and computation ability, we can use it to perform the job.

In ServiceDefinition.csdef, add
< LocalStorage name="edmondLocal" sizeInMB="4"/ >

Then, in your webrole program, use
//Setup local file storage
ILocalResource resource = RoleManager.GetLocalResource("edmondLocal");
string path = Path.Combine(resource.RootPath, "tmp.txt");
//Get Azure Blob
using (FileStream read = File.Open(path, FileMode.OpenOrCreate))
{
BlobContents contents = new BlobContents(read);
//BlobProperties blob = this._container.GetBlob(blobName, contents, true);
BlobProperties blob = this._container.GetBlob("file_AzureTest.txt", contents, true);
read.Close();
}



Job is done! Now you have the file in your windows azure local file storage.

When this internship ends in Aug I'll back to school. I'll be graduating this December, I'm looking for a job... Is there any possibility someone reads my post, see what I can do, and offer me a job?...

No comments:

Post a Comment