Azure offers Blob Storage as the cloud storage solution. Blob Storage is a way of storing substantial amounts of unstructured data: data that doesn’t adhere to a specific data model or definition- data that can’t go into rows and columns. For example, video, audio, image, log files, text files, etc. Azure Blob Storage has three types of resources to offer:
- The Storage Account
- Container(s) within the storage account
- Blob(s) within the Container
Prerequisites
- Azure Subscription
- Azure Storage Account
- The current .Net Core SDK for your OS
First, you will need to set up a .NET Core project. Do this with whichever method you please. I typically use Visual Studios, but some prefer doing this directly in their Terminal of choice.
Next, you will need to connect your Storage Account to your .NET Core project. Do this by generating an Access Key inside your Azure Storage Account. Copy the “Connection String” value generated for key1.
Then, set this value as an environment variable named “AZURE_STORAGE_CONNECTION_STRING”. An easy way to set an environment variable without navigating through your system settings is to use your OS Command Prompt. For windows, that would be the CMD with the following syntax:
|
|
.Net classes to interact with Azure Storage Resources
BlobServiceClient: manipulate Azure Storage resources and blob containers
BlobContainerClient: manipulate Azure Storage containers and their blobs
BlobClient: manipulate Azure Storage Blobs
BlobDownloadInfo: Represent the properties and content returned from downloading a Blob
Tip:
Retrieve the Azure Storage Account’s Connection String inside your .NET
project- From your previously set environment variables.
|
|
Tip:
Add the Azure Blob Storage .Net Client Library with the using statement.
|
|
Code Examples:
Retrieve the Azure Store Account’s Connection String – Environment Variable:
|
|
List Blobs in a Container:
|
|
Download Contents from each Blob in a Container to Local:
|
|
Clear Local File Path:
|
|
Open and Read File Contents to Class:
|
|