Setting up Connection to Storage Account Blob
Introduction
Required Packages
Code Block
Using Statements
# Using Statements
using Azure.Identity;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized; // You may not need this one
# Namespace and class setup removed for brevity
# The below goes inside your method
# Convert base64 to Memory Stream
string base64Content = "<some base64 string here>";
byte[] content = Convert.FromBase64String(base64Content);
MemoryStream ms = new MemoryStream(content);
# Storage Blob Connection
string storageAccountName = "<your storage account name here>";
string blobName = "<blob name here>";
BlobServiceClient serviceClient = new(
new Uri($"https://{storageAccountName}.blob.core.windows.net"),
new DefaultAzureCredential()
);
BlobContainerClient blobContainerClient;
blobContainerClient = serviceClient.GetBlobContainerClient("checklistuploads");
await blobContainerClient.CreateIfNotExistsAsync(
PublicAccessType.None, null, null, cancellationToken
);
BlobClient blobClient = blobContainerClient.GetBlobClient(fullPath);
await blobClient.UploadAsync(contents, true, cancellationToken);Final Comments
Last updated