<PackageReference Include="Azure.Storage.Blobs" Version="12.26.0-beta.1" />

AppendBlobClient

The AppendBlobClient allows you to manipulate Azure Storage append blobs. An append blob is comprised of blocks and is optimized for append operations. When you modify an append blob, blocks are added to the end of the blob only, via the AppendBlockAsync operation. Updating or deleting of existing blocks is not supported. Unlike a block blob, an append blob does not expose its block IDs. Each block in an append blob can be a different size. Beginning with x-ms-version 2022-11-02, the maximum append size is 100 MB. For previous versions, the maximum append size is 4 MB. Append blobs can include up to 50,000 blocks.
using Azure.Core; using Azure.Core.Pipeline; using Azure.Storage.Blobs.Models; using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; namespace Azure.Storage.Blobs.Specialized { public class AppendBlobClient : BlobBaseClient { private readonly AppendBlobRestClient _appendBlobRestClient; public virtual int AppendBlobMaxAppendBlockBytes { get { if (ClientConfiguration.Version >= BlobClientOptions.ServiceVersion.V2022_11_02) return 104857600; return 4194304; } } public virtual int AppendBlobMaxBlocks => 50000; internal virtual AppendBlobRestClient AppendBlobRestClient => _appendBlobRestClient; protected AppendBlobClient() { } public AppendBlobClient(string connectionString, string blobContainerName, string blobName) : base(connectionString, blobContainerName, blobName) { _appendBlobRestClient = BuildAppendBlobRestClient(_uri); } public AppendBlobClient(string connectionString, string blobContainerName, string blobName, BlobClientOptions options) : base(connectionString, blobContainerName, blobName, options) { _appendBlobRestClient = BuildAppendBlobRestClient(_uri); AssertNoClientSideEncryption(options); } public AppendBlobClient(Uri blobUri, BlobClientOptions options = null) : base(blobUri, options) { AssertNoClientSideEncryption(options); _appendBlobRestClient = BuildAppendBlobRestClient(blobUri); } public AppendBlobClient(Uri blobUri, StorageSharedKeyCredential credential, BlobClientOptions options = null) : base(blobUri, credential, options) { AssertNoClientSideEncryption(options); _appendBlobRestClient = BuildAppendBlobRestClient(blobUri); } public AppendBlobClient(Uri blobUri, AzureSasCredential credential, BlobClientOptions options = null) : base(blobUri, credential, options) { AssertNoClientSideEncryption(options); _appendBlobRestClient = BuildAppendBlobRestClient(blobUri); } public AppendBlobClient(Uri blobUri, TokenCredential credential, BlobClientOptions options = null) : base(blobUri, credential, options) { AssertNoClientSideEncryption(options); _appendBlobRestClient = BuildAppendBlobRestClient(blobUri); } internal AppendBlobClient(Uri blobUri, BlobClientConfiguration clientConfiguration) : base(blobUri, clientConfiguration, null) { _appendBlobRestClient = BuildAppendBlobRestClient(blobUri); } private static void AssertNoClientSideEncryption(BlobClientOptions options) { if (options?._clientSideEncryptionOptions != null) throw Errors.ClientSideEncryption.TypeNotSupported(typeof(AppendBlobClient)); } private AppendBlobRestClient BuildAppendBlobRestClient(Uri blobUri) { return new AppendBlobRestClient(_clientConfiguration.ClientDiagnostics, _clientConfiguration.Pipeline, blobUri.AbsoluteUri, _clientConfiguration.Version.ToVersionString()); } public new AppendBlobClient WithSnapshot(string snapshot) { return new AppendBlobClient(new BlobUriBuilder(Uri) { Snapshot = snapshot }.ToUri(), ClientConfiguration); } public new AppendBlobClient WithVersion(string versionId) { return new AppendBlobClient(new BlobUriBuilder(Uri) { VersionId = versionId }.ToUri(), ClientConfiguration); } public new AppendBlobClient WithCustomerProvidedKey(CustomerProvidedKey? customerProvidedKey) { BlobClientConfiguration blobClientConfiguration = BlobClientConfiguration.DeepCopy(ClientConfiguration); blobClientConfiguration.CustomerProvidedKey = customerProvidedKey; return new AppendBlobClient(Uri, blobClientConfiguration); } public new AppendBlobClient WithEncryptionScope(string encryptionScope) { BlobClientConfiguration blobClientConfiguration = BlobClientConfiguration.DeepCopy(ClientConfiguration); blobClientConfiguration.EncryptionScope = encryptionScope; return new AppendBlobClient(Uri, blobClientConfiguration); } public virtual Response<BlobContentInfo> Create(AppendBlobCreateOptions options, CancellationToken cancellationToken = default(CancellationToken)) { return CreateInternal(options?.HttpHeaders, options?.Metadata, options?.Tags, options?.Conditions, options?.ImmutabilityPolicy, options?.HasLegalHold, false, cancellationToken, null).EnsureCompleted(); } [AsyncStateMachine(typeof(<CreateAsync>d__22))] public virtual Task<Response<BlobContentInfo>> CreateAsync(AppendBlobCreateOptions options, CancellationToken cancellationToken = default(CancellationToken)) { <CreateAsync>d__22 stateMachine = default(<CreateAsync>d__22); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobContentInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.options = options; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [EditorBrowsable(EditorBrowsableState.Never)] public virtual Response<BlobContentInfo> Create(BlobHttpHeaders httpHeaders = null, IDictionary<string, string> metadata = null, AppendBlobRequestConditions conditions = null, CancellationToken cancellationToken = default(CancellationToken)) { return CreateInternal(httpHeaders, metadata, null, conditions, null, null, false, cancellationToken, null).EnsureCompleted(); } [AsyncStateMachine(typeof(<CreateAsync>d__24))] [EditorBrowsable(EditorBrowsableState.Never)] public virtual Task<Response<BlobContentInfo>> CreateAsync(BlobHttpHeaders httpHeaders = null, IDictionary<string, string> metadata = null, AppendBlobRequestConditions conditions = null, CancellationToken cancellationToken = default(CancellationToken)) { <CreateAsync>d__24 stateMachine = default(<CreateAsync>d__24); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobContentInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.httpHeaders = httpHeaders; stateMachine.metadata = metadata; stateMachine.conditions = conditions; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } public virtual Response<BlobContentInfo> CreateIfNotExists(AppendBlobCreateOptions options, CancellationToken cancellationToken = default(CancellationToken)) { return CreateIfNotExistsInternal(options?.HttpHeaders, options?.Metadata, immutabilityPolicy: options?.ImmutabilityPolicy, legalHold: options?.HasLegalHold, tags: options?.Tags, async: false, cancellationToken: cancellationToken).EnsureCompleted(); } [AsyncStateMachine(typeof(<CreateIfNotExistsAsync>d__26))] public virtual Task<Response<BlobContentInfo>> CreateIfNotExistsAsync(AppendBlobCreateOptions options, CancellationToken cancellationToken = default(CancellationToken)) { <CreateIfNotExistsAsync>d__26 stateMachine = default(<CreateIfNotExistsAsync>d__26); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobContentInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.options = options; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [EditorBrowsable(EditorBrowsableState.Never)] public virtual Response<BlobContentInfo> CreateIfNotExists(BlobHttpHeaders httpHeaders = null, IDictionary<string, string> metadata = null, CancellationToken cancellationToken = default(CancellationToken)) { return CreateIfNotExistsInternal(httpHeaders, metadata, null, null, null, false, cancellationToken).EnsureCompleted(); } [AsyncStateMachine(typeof(<CreateIfNotExistsAsync>d__28))] [EditorBrowsable(EditorBrowsableState.Never)] public virtual Task<Response<BlobContentInfo>> CreateIfNotExistsAsync(BlobHttpHeaders httpHeaders = null, IDictionary<string, string> metadata = null, CancellationToken cancellationToken = default(CancellationToken)) { <CreateIfNotExistsAsync>d__28 stateMachine = default(<CreateIfNotExistsAsync>d__28); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobContentInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.httpHeaders = httpHeaders; stateMachine.metadata = metadata; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [AsyncStateMachine(typeof(<CreateIfNotExistsInternal>d__29))] private Task<Response<BlobContentInfo>> CreateIfNotExistsInternal(BlobHttpHeaders httpHeaders, IDictionary<string, string> metadata, IDictionary<string, string> tags, BlobImmutabilityPolicy immutabilityPolicy, bool? legalHold, bool async, CancellationToken cancellationToken) { <CreateIfNotExistsInternal>d__29 stateMachine = default(<CreateIfNotExistsInternal>d__29); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobContentInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.httpHeaders = httpHeaders; stateMachine.metadata = metadata; stateMachine.tags = tags; stateMachine.immutabilityPolicy = immutabilityPolicy; stateMachine.legalHold = legalHold; stateMachine.async = async; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [AsyncStateMachine(typeof(<CreateInternal>d__30))] private Task<Response<BlobContentInfo>> CreateInternal(BlobHttpHeaders httpHeaders, IDictionary<string, string> metadata, IDictionary<string, string> tags, AppendBlobRequestConditions conditions, BlobImmutabilityPolicy immutabilityPolicy, bool? legalHold, bool async, CancellationToken cancellationToken, string operationName = null) { <CreateInternal>d__30 stateMachine = default(<CreateInternal>d__30); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobContentInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.httpHeaders = httpHeaders; stateMachine.metadata = metadata; stateMachine.tags = tags; stateMachine.conditions = conditions; stateMachine.immutabilityPolicy = immutabilityPolicy; stateMachine.legalHold = legalHold; stateMachine.async = async; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [EditorBrowsable(EditorBrowsableState.Never)] public virtual Response<BlobAppendInfo> AppendBlock(Stream content, byte[] transactionalContentHash, AppendBlobRequestConditions conditions, IProgress<long> progressHandler, CancellationToken cancellationToken) { return AppendBlockInternal(content, transactionalContentHash.ToValidationOptions(), conditions, progressHandler, false, cancellationToken).EnsureCompleted(); } [AsyncStateMachine(typeof(<AppendBlockAsync>d__32))] [EditorBrowsable(EditorBrowsableState.Never)] public virtual Task<Response<BlobAppendInfo>> AppendBlockAsync(Stream content, byte[] transactionalContentHash, AppendBlobRequestConditions conditions, IProgress<long> progressHandler, CancellationToken cancellationToken) { <AppendBlockAsync>d__32 stateMachine = default(<AppendBlockAsync>d__32); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobAppendInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.content = content; stateMachine.transactionalContentHash = transactionalContentHash; stateMachine.conditions = conditions; stateMachine.progressHandler = progressHandler; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } public virtual Response<BlobAppendInfo> AppendBlock(Stream content, AppendBlobAppendBlockOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return AppendBlockInternal(content, options?.TransferValidation, options?.Conditions, options?.ProgressHandler, false, cancellationToken).EnsureCompleted(); } [AsyncStateMachine(typeof(<AppendBlockAsync>d__34))] public virtual Task<Response<BlobAppendInfo>> AppendBlockAsync(Stream content, AppendBlobAppendBlockOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { <AppendBlockAsync>d__34 stateMachine = default(<AppendBlockAsync>d__34); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobAppendInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.content = content; stateMachine.options = options; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [AsyncStateMachine(typeof(<AppendBlockInternal>d__35))] internal Task<Response<BlobAppendInfo>> AppendBlockInternal(Stream content, UploadTransferValidationOptions transferValidationOverride, AppendBlobRequestConditions conditions, IProgress<long> progressHandler, bool async, CancellationToken cancellationToken) { <AppendBlockInternal>d__35 stateMachine = default(<AppendBlockInternal>d__35); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobAppendInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.content = content; stateMachine.transferValidationOverride = transferValidationOverride; stateMachine.conditions = conditions; stateMachine.progressHandler = progressHandler; stateMachine.async = async; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } public virtual Response<BlobAppendInfo> AppendBlockFromUri(Uri sourceUri, AppendBlobAppendBlockFromUriOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return AppendBlockFromUriInternal(sourceUri, options?.SourceRange ?? default(HttpRange), options?.SourceContentHash, options?.DestinationConditions, options?.SourceConditions, options?.SourceAuthentication, options?.SourceShareTokenIntent, false, cancellationToken).EnsureCompleted(); } [AsyncStateMachine(typeof(<AppendBlockFromUriAsync>d__37))] public virtual Task<Response<BlobAppendInfo>> AppendBlockFromUriAsync(Uri sourceUri, AppendBlobAppendBlockFromUriOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { <AppendBlockFromUriAsync>d__37 stateMachine = default(<AppendBlockFromUriAsync>d__37); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobAppendInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.sourceUri = sourceUri; stateMachine.options = options; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [EditorBrowsable(EditorBrowsableState.Never)] public virtual Response<BlobAppendInfo> AppendBlockFromUri(Uri sourceUri, HttpRange sourceRange, byte[] sourceContentHash, AppendBlobRequestConditions conditions, AppendBlobRequestConditions sourceConditions, CancellationToken cancellationToken) { return AppendBlockFromUriInternal(sourceUri, sourceRange, sourceContentHash, conditions, sourceConditions, null, null, false, cancellationToken).EnsureCompleted(); } [AsyncStateMachine(typeof(<AppendBlockFromUriAsync>d__39))] [EditorBrowsable(EditorBrowsableState.Never)] public virtual Task<Response<BlobAppendInfo>> AppendBlockFromUriAsync(Uri sourceUri, HttpRange sourceRange, byte[] sourceContentHash, AppendBlobRequestConditions conditions, AppendBlobRequestConditions sourceConditions, CancellationToken cancellationToken) { <AppendBlockFromUriAsync>d__39 stateMachine = default(<AppendBlockFromUriAsync>d__39); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobAppendInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.sourceUri = sourceUri; stateMachine.sourceRange = sourceRange; stateMachine.sourceContentHash = sourceContentHash; stateMachine.conditions = conditions; stateMachine.sourceConditions = sourceConditions; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [AsyncStateMachine(typeof(<AppendBlockFromUriInternal>d__40))] private Task<Response<BlobAppendInfo>> AppendBlockFromUriInternal(Uri sourceUri, HttpRange sourceRange, byte[] sourceContentHash, AppendBlobRequestConditions conditions, AppendBlobRequestConditions sourceConditions, HttpAuthorization sourceAuthentication, FileShareTokenIntent? sourceShareTokenIntent, bool async, CancellationToken cancellationToken = default(CancellationToken)) { <AppendBlockFromUriInternal>d__40 stateMachine = default(<AppendBlockFromUriInternal>d__40); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobAppendInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.sourceUri = sourceUri; stateMachine.sourceRange = sourceRange; stateMachine.sourceContentHash = sourceContentHash; stateMachine.conditions = conditions; stateMachine.sourceConditions = sourceConditions; stateMachine.sourceAuthentication = sourceAuthentication; stateMachine.sourceShareTokenIntent = sourceShareTokenIntent; stateMachine.async = async; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } public virtual Response<BlobInfo> Seal(AppendBlobRequestConditions conditions = null, CancellationToken cancellationToken = default(CancellationToken)) { return SealInternal(conditions, false, cancellationToken).EnsureCompleted(); } [AsyncStateMachine(typeof(<SealAsync>d__42))] public virtual Task<Response<BlobInfo>> SealAsync(AppendBlobRequestConditions conditions = null, CancellationToken cancellationToken = default(CancellationToken)) { <SealAsync>d__42 stateMachine = default(<SealAsync>d__42); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.conditions = conditions; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [AsyncStateMachine(typeof(<SealInternal>d__43))] private Task<Response<BlobInfo>> SealInternal(AppendBlobRequestConditions conditions, bool async, CancellationToken cancellationToken) { <SealInternal>d__43 stateMachine = default(<SealInternal>d__43); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Response<BlobInfo>>.Create(); stateMachine.<>4__this = this; stateMachine.conditions = conditions; stateMachine.async = async; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } public virtual Stream OpenWrite(bool overwrite, AppendBlobOpenWriteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return OpenWriteInternal(overwrite, options, false, cancellationToken).EnsureCompleted(); } [AsyncStateMachine(typeof(<OpenWriteAsync>d__45))] public virtual Task<Stream> OpenWriteAsync(bool overwrite, AppendBlobOpenWriteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { <OpenWriteAsync>d__45 stateMachine = default(<OpenWriteAsync>d__45); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Stream>.Create(); stateMachine.<>4__this = this; stateMachine.overwrite = overwrite; stateMachine.options = options; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } [AsyncStateMachine(typeof(<OpenWriteInternal>d__46))] private Task<Stream> OpenWriteInternal(bool overwrite, AppendBlobOpenWriteOptions options, bool async, CancellationToken cancellationToken) { <OpenWriteInternal>d__46 stateMachine = default(<OpenWriteInternal>d__46); stateMachine.<>t__builder = AsyncTaskMethodBuilder<Stream>.Create(); stateMachine.<>4__this = this; stateMachine.overwrite = overwrite; stateMachine.options = options; stateMachine.async = async; stateMachine.cancellationToken = cancellationToken; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } } }