Search code examples
c#.netazure-blob-storageazure-sdk-.net

What is the difference between the Azure Storage BlobClient and BlockBlobClient in v12 .NET SDK?


I've looked around but can't seem to find anywhere in docs and the Intellisense documentation for these APIs is nearly identical.

What is the difference between an Azure Storage BlockBlobClient and a BlobClient in the Azure Storage v12 SDK?

Which one should I be using for efficiently uploading file streams to Azure Blob Storage using the Azure Storage v12 .NET SDK?

Is there any difference between these two bits of code and how they get files up to the cloud??

var container = _blobServiceClient.GetBlobContainerClient(containerName);

var blobClient = container.GetBlobClient(filename); // this?
var blockBlockClient = container.GetBlockBlobClient(filename); // or this?

Solution

  • Azure Blob Storage supports three kinds of blobs - Block, Page and Append. While a lot of operations are common for all of these blobs (like delete, copy, lease etc.), there are some operations which are specific to a blob type (like put block, put block list for block blobs). To see operations specific to a particular blob type, please see this: https://learn.microsoft.com/en-us/rest/api/storageservices/operations-on-blobs.

    BlobClient provides functionality which can be used for all kinds of blobs.

    However to deal with functionality only available with specific kind of blob, you will need to use a client specific for that e.g. BlockBlobClient to deal with block blobs, AppendBlobClient to deal with append blobs and PageBlobClient to deal with page blobs.