HI WELCOME TO KANSIRIS

Azure Blob Creation

Leave a Comment

 

Step 1: Nuget Package

Add WindowsAzure.Storage Nuget Package

Step 2: Add class File

Add Below Namespaces

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;

Add below code
public async Task<bool> Createblob(string containerName)
{
bool response = false;
string azureStorageAccessKey = “your Azure Storage Access Key”;

// Create private container if connection string is valid
if (CloudStorageAccount.TryParse(azureStorageAccessKey, out CloudStorageAccount cloudStorageAccount))
{
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
var blobContainer = cloudBlobClient.GetContainerReference(containerName.ToLower());
if (!await blobContainer.ExistsAsync())
{
await blobContainer.CreateAsync();
}
// Explicitly revoke public access to ensure that container is created private
await blobContainer.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Off });
return response = true;
}
else
{
Console.WriteLine(“Unable to create container due to invalid Storage Account connection string.”);
return response;
}
}

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.