This post is about uploading and downloading images from Azure Blob storage using ASP.NET Core. First you need to create a blob storage account and then a container which you’ll use to store all the images. You can do this from Azure portal. You need to select Storage > Storage Account - Blob, file, Table, Queue > Create a Storage Account.
Once you created a storage account, you need to create a container, you can create container from Containers menu under Blob Service. You need to provide a name and change the access type to Blob.
You need to use access keys to authenticate your applications when making requests to this Azure storage account. You can get the access keys from Settings > Access Keys. You can copy the connection string from the portal and can be used in the appsettings.json file.
For accessing the azure storage account, you need
WindowsAzure.Storage package reference. Here is my CSProj.
For uploading, you need to create an instance of CloudStorageAccount, then you need to create Blob client. Once you get the blob client instance, you need to get the container reference, by providing the container name. Using the container, you can get the blob reference, which will help you to upload the file to blob storage. Here is the code.
And you can get the images from Container using the
You can enumerate on the
listBlobItems.Results property and can get all the files in the specified container. The
ListBlobsSegmentedAsync() method helps you to configure paging and type of results etc.
Happy Programming :)