Azure

Microsoft Azure Storage Blob Information Add, Obtain And Delete In Net API

Introduction

On this article, I’ve defined Azure Blob storage, and it’ll assist you to grasp find out how to retailer, obtain, and delete information from Azure storage.

Mainly, it is a Microsoft object storage answer for the cloud and lets you retailer big quantities of unstructured information. Unstructured information are noting however, it’s textual content and binary information.

Azure container identify have to be lowercase.

Microsoft Azure Storage helps three kinds of blobs,

  1. Block blobs
    It can retailer the textual content and binary information’s and individually managed the blocks of knowledge with blobs. Usually block blobs retailer as much as 190.7 TiB.
     
  2. Append blobs
    It’s like block blobs. However, optimized for the append operations and append blobs best situations in logging information from digital machines.
     
  3. Web page blobs
    Web page blobs retailer digital onerous drive information and function disks for Azure digital machines, and they’re going to retailer the random-access information as much as eight TiB

Stipulations

  • Set up-Package deal Microsoft.Azure.Storage.Blob -Model 11.2.3

Add the information in Microsoft Azure storage blob

Usually you possibly can add the information with assist of the UploadFromStream() methodology within the blobs storage, under code will make it easier to to add the information within the Azure storage blob with c# within the net API challenge. You must know the Container Identify, Archive Storage Account, Storage Key to add the information in Azure Storage Blob.

byte[] imageBytes = Convert.FromBase64String("Your Server Picture");
string BlobContainerName = "Your Blob BlobContainerName";
string AzureArchiveStorageAccount = "Your Blob AzureArchiveStorageAccount";
string AzureArchiveStorageKey = "Your Blob AzureArchiveStorageKey";
utilizing(var stream = new MemoryStream(imageBytes)) {
    StorageCredentials credentials = new StorageCredentials(AzureArchiveStorageAccount, AzureArchiveStorageKey);
    CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, useHttps: true);
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
    CloudBlobContainer cloudBlobContainer = blobClient.GetContainerReference(BlobContainerName);
    CloudBlockBlob cblob = cloudBlobContainer.GetBlockBlobReference("ImageName.png");
    cblob.UploadFromStream(stream);
}

Obtain the information in Microsoft Azure storage blob

You possibly can obtain the information with the assistance of DownloadToStream() methodology within the blobs. The under code will make it easier to to obtain the information within the Azure storage blob with c# within the net API challenge. You must know the Container Identify, Archive Storage Account, Storage Key to add the information in Azure Storage Blob.

string BlobContainerName = "Your Blob BlobContainerName";
string AzureArchiveStorageAccount = "Your Blob AzureArchiveStorageAccount";
string AzureArchiveStorageKey = "Your Blob AzureArchiveStorageKey";
utilizing(var stream = new MemoryStream(imageBytes)) {
    StorageCredentials credentials = new StorageCredentials(AzureArchiveStorageAccount, AzureArchiveStorageKey);
    CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, useHttps: true);
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
    CloudBlobContainer cloudBlobContainer = blobClient.GetContainerReference(BlobContainerName);
    CloudBlockBlob cblob = cloudBlobContainer.GetBlockBlobReference("ImageName.png");
    MemoryStream memStream = new MemoryStream();
    cblob.DownloadToStream(memStream);
}

Delete the information within the Microsoft Azure storage blob

You possibly can Delete the information with assist of the DeleteIfExists() methodology within the blobs. The under coding will make it easier to to delete the information within the Azure storage blob with c# language within the net API challenge. You must know the Container Identify, Archive Storage Account, Storage Key to add the information in Azure Storage Blob.

string BlobContainerName = "Your Blob BlobContainerName";
string AzureArchiveStorageAccount = "Your Blob AzureArchiveStorageAccount";
string AzureArchiveStorageKey = "Your Blob AzureArchiveStorageKey";
utilizing(var stream = new MemoryStream(imageBytes)) {
    StorageCredentials credentials = new StorageCredentials(AzureArchiveStorageAccount, AzureArchiveStorageKey);
    CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, useHttps: true);
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
    CloudBlobContainer cloudBlobContainer = blobClient.GetContainerReference(BlobContainerName);
    CloudBlockBlob cblob = cloudBlobContainer.GetBlockBlobReference("ImageName.png");
    bool blobExists = cblob.DeleteIfExists();
}

Hopefully, this text has given you enough info to begin Microsoft Azure storage blob information add, obtain, and delete in net API. Be happy to go away a remark if you want me to additional elaborate on something inside this text.

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button