2

I have a WCF service hosted in Azure.

I have a spatialite database file I'm going to keep in Azure blob storage (1.1G). Compressed it is 500K.

I would like to copy it to local storage when my service starts, and then use spatialite to run various spatial functions off the database file. The spatial data is static.

Does anybody have a code snippet (C#) to copy a file from azure blob storage to local storage?

(also, I think this approach makes sense - does it?)

(also, should I bother compressing the file for blob storage?)

Thanks

EDIT: Thanks for the first two responses. I was hoping for some code snippets to use. I could use a little more explanation on which would be the better route to go. Just code it all or use this bootstrap idea.

SOLUTION: I'm marking SMARX's as answer because it should work for any protected azure file, but since the file is a publicly available blob file, I skipped the CloudStorageAccount route suggested by SMARX, in favor of simple web access. I'm wondering if there are any speed advantages to using SMARX's approach though. Any comments would be appreciated.

// Retrieve an object that points to the local storage resource
LocalResource localResource = RoleEnvironment.GetLocalResource("MyLocalStorage");

WebClient webClient = new WebClient();
webClient.DownloadFile(blobUrl, localResource.RootPath + "mySpatialiteDB.sqlite");

NOTE: You have to configure the local storage through your webRole properties

2
  • Using the SDK, use the GetBlob API function - or simply use the REST call of: myaccount.blob.core.windows.net/mycontainer/myblob That's a pretty small file, so the compression may not be worth it from a computation standpoint. Commented Oct 5, 2011 at 20:02
  • You can use a startup task to download the blob. Interestingly enough, there is a tool called bootstrapper that will download and unzip for you from blob storage. Check it out here: bootstrap.codeplex.com Commented Oct 5, 2011 at 20:17

1 Answer 1

2

How about: CloudStorageAccount.Parse(...).CreateCloudBlobClient().GetBlobReference("path/of/blob").DownloadFile(RoleEnvironment.GetLocalResource("nameOfLocalResource").RootPath);

Do that in your RoleEntryPoint in OnStart before you do anything else?

Sign up to request clarification or add additional context in comments.

4 Comments

That's more like it! One statement and done. How would I set this up so it doesn't try to download this file when I'm running locally? (i.e. bypass the load when running locally, but use it when on the cloud)
Wrap in if (!RoleEnviornment.IsEmulated). (New in SDK 1.5.)
I think this is the answer, once I have it working, I'll mark it as such and post working code
And, of course, I meant RoleEnvironment (misspelled it above).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.