Azure.Storage.Blobs.Batch
12.19.0
Prefix Reserved
See the version list below for details.
dotnet add package Azure.Storage.Blobs.Batch --version 12.19.0
NuGet\Install-Package Azure.Storage.Blobs.Batch -Version 12.19.0
<PackageReference Include="Azure.Storage.Blobs.Batch" Version="12.19.0" />
paket add Azure.Storage.Blobs.Batch --version 12.19.0
#r "nuget: Azure.Storage.Blobs.Batch, 12.19.0"
// Install Azure.Storage.Blobs.Batch as a Cake Addin #addin nuget:?package=Azure.Storage.Blobs.Batch&version=12.19.0 // Install Azure.Storage.Blobs.Batch as a Cake Tool #tool nuget:?package=Azure.Storage.Blobs.Batch&version=12.19.0
Azure Storage Blobs Batch client library for .NET
Server Version: 2021-02-12, 2020-12-06, 2020-10-02, 2020-08-04, 2020-06-12, 2020-04-08, 2020-02-10, 2019-12-12, 2019-07-07, and 2019-02-02
Azure Blob storage is Microsoft's object storage solution for the cloud. Blob storage is optimized for storing massive amounts of unstructured data. This library allows you to batch multiple Azure Blob Storage operations in a single request.
Source code | Package (NuGet) | API reference documentation | REST API documentation | Product documentation
Getting started
Install the package
Install the Azure Storage Blobs Batch client library for .NET with NuGet:
dotnet add package Azure.Storage.Blobs.Batch
Prerequisites
You need an Azure subscription and a Storage Account to use this package.
To create a new Storage Account, you can use the Azure Portal, Azure PowerShell, or the Azure CLI. Here's an example using the Azure CLI:
az storage account create --name MyStorageAccount --resource-group MyResourceGroup --location westus --sku Standard_LRS
Authenticate the client
In order to interact with the Azure Blobs Storage service for batch operations, you'll need to create an instance of the BlobServiceClient class. The Azure Identity library makes it easy to add Azure Active Directory support for authenticating Azure SDK clients with their corresponding Azure services.
// Create a BlobServiceClient that will authenticate through Active Directory
Uri accountUri = new Uri("https://MYSTORAGEACCOUNT.blob.core.windows.net/");
BlobServiceClient client = new BlobServiceClient(accountUri, new DefaultAzureCredential());
BlobBatchClient batch = client.GetBlobBatchClient();
Key concepts
Batching supports two types of subrequests: SetBlobAccessTier for block blobs and DeleteBlob for blobs.
- Only supports up to 256 subrequests in a single batch. The size of the body for a batch request cannot exceed 4MB.
- There are no guarantees on the order of execution of the batch subrequests.
- Batch subrequest execution is not atomic. Each subrequest is executed independently.
- Each subrequest must be for a resource within the same storage account.
Thread safety
We guarantee that all client instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing client instances is always safe, even across threads.
Additional concepts
Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime
Examples
Deleting blobs
// Get a connection string to our Azure Storage account.
string connectionString = "<connection_string>";
string containerName = "sample-container";
// Get a reference to a container named "sample-container" and then create it
BlobServiceClient service = new BlobServiceClient(connectionString);
BlobContainerClient container = service.GetBlobContainerClient(containerName);
container.Create();
// Create three blobs named "foo", "bar", and "baz"
BlobClient foo = container.GetBlobClient("foo");
BlobClient bar = container.GetBlobClient("bar");
BlobClient baz = container.GetBlobClient("baz");
foo.Upload(BinaryData.FromString("Foo!"));
bar.Upload(BinaryData.FromString("Bar!"));
baz.Upload(BinaryData.FromString("Baz!"));
// Delete all three blobs at once
BlobBatchClient batch = service.GetBlobBatchClient();
batch.DeleteBlobs(new Uri[] { foo.Uri, bar.Uri, baz.Uri });
Setting Access Tiers
// Get a connection string to our Azure Storage account.
string connectionString = "<connection_string>";
string containerName = "sample-container";
// Get a reference to a container named "sample-container" and then create it
BlobServiceClient service = new BlobServiceClient(connectionString);
BlobContainerClient container = service.GetBlobContainerClient(containerName);
container.Create();
// Create three blobs named "foo", "bar", and "baz"
BlobClient foo = container.GetBlobClient("foo");
BlobClient bar = container.GetBlobClient("bar");
BlobClient baz = container.GetBlobClient("baz");
foo.Upload(BinaryData.FromString("Foo!"));
bar.Upload(BinaryData.FromString("Bar!"));
baz.Upload(BinaryData.FromString("Baz!"));
// Set the access tier for all three blobs at once
BlobBatchClient batch = service.GetBlobBatchClient();
batch.SetBlobsAccessTier(new Uri[] { foo.Uri, bar.Uri, baz.Uri }, AccessTier.Cool);
Fine-grained control
// Get a connection string to our Azure Storage account.
string connectionString = "<connection_string>";
string containerName = "sample-container";
// Get a reference to a container named "sample-container" and then create it
BlobServiceClient service = new BlobServiceClient(connectionString);
BlobContainerClient container = service.GetBlobContainerClient(containerName);
container.Create();
// Create three blobs named "foo", "bar", and "baz"
BlobClient foo = container.GetBlobClient("foo");
BlobClient bar = container.GetBlobClient("bar");
BlobClient baz = container.GetBlobClient("baz");
foo.Upload(BinaryData.FromString("Foo!"));
foo.CreateSnapshot();
bar.Upload(BinaryData.FromString("Bar!"));
bar.CreateSnapshot();
baz.Upload(BinaryData.FromString("Baz!"));
// Create a batch with three deletes
BlobBatchClient batchClient = service.GetBlobBatchClient();
BlobBatch batch = batchClient.CreateBatch();
batch.DeleteBlob(foo.Uri, DeleteSnapshotsOption.IncludeSnapshots);
batch.DeleteBlob(bar.Uri, DeleteSnapshotsOption.OnlySnapshots);
batch.DeleteBlob(baz.Uri);
// Submit the batch
batchClient.SubmitBatch(batch);
Troubleshooting
All Blob service operations will throw a
RequestFailedException on failure with
helpful ErrorCode
s. Many of these errors are recoverable. Subrequest failures will be bundled together into an AggregateException.
// Get a connection string to our Azure Storage account.
string connectionString = "<connection_string>";
string containerName = "sample-container";
// Get a reference to a container named "sample-container" and then create it
BlobServiceClient service = new BlobServiceClient(connectionString);
BlobContainerClient container = service.GetBlobContainerClient(containerName);
container.Create();
// Create a blob named "valid"
BlobClient valid = container.GetBlobClient("valid");
valid.Upload(BinaryData.FromString("Valid!"));
// Get a reference to a blob named "invalid", but never create it
BlobClient invalid = container.GetBlobClient("invalid");
// Delete both blobs at the same time
BlobBatchClient batch = service.GetBlobBatchClient();
try
{
batch.DeleteBlobs(new Uri[] { valid.Uri, invalid.Uri });
}
catch (AggregateException)
{
// An aggregate exception is thrown for all the individual failures
// Check ex.InnerExceptions for RequestFailedException instances
}
Next steps
Check out our sync and async samples for more.
Contributing
See the Storage CONTRIBUTING.md for details on building, testing, and contributing to this library.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Azure.Storage.Blobs (>= 12.22.0)
- Azure.Storage.Common (>= 12.21.0)
-
net6.0
- Azure.Storage.Blobs (>= 12.22.0)
- Azure.Storage.Common (>= 12.21.0)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on Azure.Storage.Blobs.Batch:
Package | Downloads |
---|---|
Wivuu.GlobalCache.AzureStorage
The GlobalCache library provides a cheap and effortless way to host a distributed caching mechanism. |
|
FileManager.Azure
A service that provides all necessary functionality to maintain your azure storage account as well as helps to create hierarchical paths for organizational purposes. |
|
BananaCakePop.Services.Azure
Contains the AssetCache for Azure Blob Storage |
|
Ramstack.FileSystem.Azure
Provides an implementation of Ramstack.FileSystem based on Azure Blob Storage. |
|
ChilliCream.Nitro.Azure
Contains the AssetCache for Azure Blob Storage |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Azure.Storage.Blobs.Batch:
Repository | Stars |
---|---|
MrCMS/MrCMS
Mr CMS is an open source C# MVC CMS Framework
|
Version | Downloads | Last updated |
---|---|---|
12.20.0 | 15,350 | 11/12/2024 |
12.20.0-beta.2 | 431 | 10/10/2024 |
12.20.0-beta.1 | 80 | 10/8/2024 |
12.19.1 | 43,039 | 10/11/2024 |
12.19.0 | 33,326 | 9/19/2024 |
12.19.0-beta.1 | 304 | 8/7/2024 |
12.18.1 | 121,319 | 7/25/2024 |
12.18.0 | 43,615 | 7/16/2024 |
12.18.0-beta.1 | 582 | 6/11/2024 |
12.17.0 | 197,909 | 5/15/2024 |
12.17.0-beta.2 | 1,004 | 4/16/2024 |
12.17.0-beta.1 | 15,330 | 12/5/2023 |
12.16.1 | 426,562 | 11/14/2023 |
12.16.0 | 123,541 | 11/6/2023 |
12.16.0-beta.1 | 406 | 10/16/2023 |
12.15.0 | 133,001 | 9/12/2023 |
12.15.0-beta.1 | 469 | 8/8/2023 |
12.14.0 | 173,081 | 7/11/2023 |
12.14.0-beta.1 | 358 | 5/30/2023 |
12.13.0 | 259,004 | 4/11/2023 |
12.13.0-beta.1 | 274 | 3/28/2023 |
12.12.1 | 178,476 | 3/24/2023 |
12.12.0 | 162,643 | 2/22/2023 |
12.12.0-beta.1 | 291 | 2/8/2023 |
12.11.0 | 409,168 | 10/12/2022 |
12.11.0-beta.1 | 541 | 8/23/2022 |
12.10.0 | 523,234 | 7/8/2022 |
12.10.0-beta.1 | 314 | 6/15/2022 |
12.9.0 | 126,299 | 5/2/2022 |
12.9.0-beta.1 | 387 | 4/12/2022 |
12.8.0 | 117,483 | 3/10/2022 |
12.8.0-beta.3 | 641 | 2/7/2022 |
12.8.0-beta.2 | 398 | 11/30/2021 |
12.8.0-beta.1 | 325 | 11/4/2021 |
12.7.0 | 393,218 | 9/9/2021 |
12.7.0-beta.2 | 402 | 7/23/2021 |
12.7.0-beta.1 | 225 | 7/23/2021 |
12.6.0 | 222,268 | 6/9/2021 |
12.6.0-beta.4 | 374 | 5/12/2021 |
12.6.0-beta.3 | 1,093 | 4/9/2021 |
12.6.0-beta.2 | 371 | 3/10/2021 |
12.6.0-beta.1 | 6,978 | 2/10/2021 |
12.5.2 | 126,798 | 5/21/2021 |
12.5.1 | 29,632 | 3/29/2021 |
12.5.0 | 104,026 | 1/12/2021 |
12.5.0-beta.1 | 507 | 12/7/2020 |
12.4.0 | 126,759 | 11/10/2020 |
12.4.0-preview.1 | 470 | 10/1/2020 |
12.3.1 | 68,414 | 8/18/2020 |
12.3.0-preview.2 | 376 | 7/28/2020 |
12.3.0-preview.1 | 349 | 7/3/2020 |
12.2.1 | 90,660 | 3/12/2020 |
12.2.0 | 4,214 | 2/11/2020 |
12.1.1 | 46,836 | 1/10/2020 |
12.1.0 | 1,284 | 12/4/2019 |
12.0.0 | 17,436 | 10/31/2019 |