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

Brad Boyce
  • 1,248
  • 1
  • 17
  • 34
  • Using the SDK, use the GetBlob API function - or simply use the REST call of: http://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. –  Oct 05 '11 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: http://bootstrap.codeplex.com – dunnry Oct 05 '11 at 20:17

1 Answers1

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?

user94559
  • 59,196
  • 6
  • 103
  • 103
  • 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) – Brad Boyce Oct 07 '11 at 00:42
  • Wrap in `if (!RoleEnviornment.IsEmulated)`. (New in SDK 1.5.) – user94559 Oct 07 '11 at 10:12
  • I think this is the answer, once I have it working, I'll mark it as such and post working code – Brad Boyce Oct 09 '11 at 14:04
  • And, of course, I meant RoleEnvironment (misspelled it above). – user94559 Oct 09 '11 at 14:47