diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs index 8df652fc58366..c91a776426f0e 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlobClient.cs @@ -1042,13 +1042,18 @@ public virtual Response Upload( public virtual Response Upload( BinaryData content, BlobUploadOptions options, - CancellationToken cancellationToken = default) => - StagedUploadInternal( - content.ToStream(), - options, - async: false, - cancellationToken: cancellationToken) - .EnsureCompleted(); + CancellationToken cancellationToken = default) + { + using (var stream = content.ToStream()) + { + return StagedUploadInternal( + stream, + options, + async: false, + cancellationToken: cancellationToken) + .EnsureCompleted(); + } + } /// /// The @@ -1360,13 +1365,18 @@ await StagedUploadInternal( public virtual async Task> UploadAsync( BinaryData content, BlobUploadOptions options, - CancellationToken cancellationToken = default) => - await StagedUploadInternal( - content.ToStream(), - options, - async: true, - cancellationToken: cancellationToken) - .ConfigureAwait(false); + CancellationToken cancellationToken = default) + { + using (var stream = content.ToStream()) + { + return await StagedUploadInternal( + stream, + options, + async: true, + cancellationToken: cancellationToken) + .ConfigureAwait(false); + } + } /// /// The diff --git a/sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs b/sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs index f5348303e57f0..f9269ce6cb893 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/BlockBlobClient.cs @@ -3238,14 +3238,18 @@ await client.StageBlockInternal( LeaseId = args.Conditions.LeaseId }; } - await client.StageBlockInternal( - Shared.StorageExtensions.GenerateBlockId(offset), - content.ToStream(), - validationOptions, - conditions, - progressHandler, - async, - cancellationToken).ConfigureAwait(false); + + using (var stream = content.ToStream()) + { + await client.StageBlockInternal( + Shared.StorageExtensions.GenerateBlockId(offset), + stream, + validationOptions, + conditions, + progressHandler, + async, + cancellationToken).ConfigureAwait(false); + } }, CommitPartitionedUpload = async (partitions, args, async, cancellationToken) => await client.CommitBlockListInternal(