We've selected our favorite tips and tricks created by Michael Crump and are delivering fresh technical content on Azure all April! Miss a day (or more)? Catch up with the series.
Don't have Azure? Grab a free subscription.
Azure Storage is described as a service which provides storage that is available, secure, durable, scalable, and redundant.
Azure Storage is an umbrella term. It covers:
We're going to focus on Blob storage for now.
Creating Blob Storage in the Azure Portal đź“‚
Go ahead and open the Azure Portal and click Create a Resource
. Select Azure Storage
. We’ll keep it simple as shown below to get started.
Once complete — the portal will notify you — go into the resource and look under Services
.
Go ahead and click on Blobs
and create a Container
and give it the name Images
.
Remember! A container is a lot like a folder.
https://myblob/container/image1.jpg
You’ll now want to click Upload
and select a file on your physical disk.
Now that your file is uploaded, select it. You can click on the ellipsis and select Blob properties
to see additional details.
Yay! You can download it or access it via the URL provided. That was pretty easy, right?
Let's do the same thing... differently.
Provisioning an Azure Storage Blob Container in C# 🗄️
Yes, the code we're using is C# but don't freak out if you don't know C# (I don't!) Michael Crump wrote this code and I think it's clear what's happening — regardless of your language of choice.
Navigate to your Azure Storage account in the portal.
Look under Settings
, then Access Keys
and copy the connection string.
Create a C# Console Application, and use NuGet to pull in references to:
- WindowsAzure.Storage
- Microsoft.WindowsAzure.ConfigurationManager
Inside of your Console app, you will see App.config
, now add the following section:
<appSettings>
<add key="StorageConnection" value="YOUR-CONNECTION-STRING-COPIED-FROM-EARLIER"/>
</appSettings>
Copy the following code into your Main method:
static void Main(string[] args)
{
var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnection"));
var myClient = storageAccount.CreateCloudBlobClient();
var container = myClient.GetContainerReference("images-backup");
container.CreateIfNotExists(BlobContainerPublicAccessType.Blob);
Console.ReadLine();
}
This code will get our connection string from the App.config
, create our client and a container named images-backup
if it doesn’t exist. We can go back inside of the portal to see if executed correctly.
Success! We’ve now accomplished the same task via the Azure Portal and C#.
Want more Azure Storage? Check out our quickstarts and tutorials!
We'll be posting articles every day in April, so stay tuned or jump ahead and check out more tips and tricks now.
Top comments (0)