Basic set up of Azure storage for local development and production.
This is a somewhat completion of the following guide from http://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/ that also involves a practical example that I believe is commonly used, i.e. upload and present an image from a user.
First we set up for local storage and then we configure for them to work on a web role.
1. Configure connection string locally.
2. Configure model, controllers and razor views.
1. Setup connectionsstring
1.1 Right click your web role and choose “Properties”.
1.2 Click Settings.
1.3 Add setting.
1.4 Name your setting. This will be the name of the connectionstring.
1.5 Click the ellipsis to the right. (the ellipsis appear when you mark the area.
1.6 The following window appears- Select “Windows Azure storage emulator” and click ok.
Now we have a connection string to use. To be able to use it we need to make sure we have windows azure tools for storage.
2.1 Click Tools –> Library Package manager –> Manage Nuget packages for solution.
2.2 This is what it looks like after it has been added.
Now on to what the code should look like.
3.1 First we need a view which collects images to upload. Here Index.cshtml.
3.2 We need a controller to receive the post. Notice the “containername” string I send to the blobhandler. I use this as a folder for the pictures for each user. If this is not a requirement you could just call it container or anything with small characters directly when creating the container.
3.3 The handler model. I’ll let the comments speak for themselves.
3.4 So, when the files have been uploaded we will get them to present them to out user in the index page. Pretty straight forward. In this example we only present the image by sending the Uri’s to the view. A better way would be to save them up in a view model containing URI, metadata, alternate text, and other relevant information but for this example this is all we need.
4. Now press F5 in your solution to try it out. You can see the storage emulator UI here:
4.1 If you get any exceptions or errors I suggest to first check if the service Is running correctly. I had problem with this and they seemed related to the installation and a reboot fixed my problems.
5. Set up for Cloud storage. To do this we need to add configuration for cloud just as we did for local in step one.
5.1 We need our keys to do this. Go to the windows Azure menagement portal, select storage icon to the right and click “Manage keys”. (Image from a different blog post though).
5.2 Do as in step 1.but replace step 1.6 with:
1.6 Choose “Manually entered credentials”. Enter your account name.
1.7 Paste your Account Key from step 5.1. and click ok.
5.3. Save, publish and run!
Please feel free to ask any questions using the comments form at the bottom of this page. I will get back to you to help you solve any questions. Our consultancy agency also provides services in the Nordic regions if you would like any further support.