[BUG] Passing BinaryData to BlobClient.UploadAsync() results in NullReferenceException when also using ClientSideEncryptionOptions
See original GitHub issueLibrary name and version
Azure.Storage.Blobs 12.10.0.0
Describe the bug
FAILS: Uploading with string content wrapped in BinaryData.
string content = "foo-bar";
BlobClient client;
// not shown here - create BlobClient using SpecializedBlobClientOptions and ClientSideEncryption
await client.UploadAsync(new BinaryData(content), true); // <-- explodes violently, and with its last breath exclaims "Object reference not set to an instance of an object."
Stack trace:
at Azure.Storage.Blobs.BlobClient+<StagedUploadInternal>d__41.MoveNext (Azure.Storage.Blobs, Version=12.10.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Azure.Storage.Blobs.BlobClient+<UploadAsync>d__37.MoveNext (Azure.Storage.Blobs, Version=12.10.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
WORKAROUND: Convert BinaryData to Stream.
await client.UploadAsync(new BinaryData(content).ToStream(), true);
OTHER: When not using ClientSideEncryptionOptions this issue does not occur.
Expected behavior
Result of passing BinaryData is equal to result of passing Stream (blob is uploaded successfully).
Actual behavior
NullReferenceException is thrown in the face of an otherwise happy developer.
Reproduction Steps
// running in app service
// common
var connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
// for blob encryption
var credential = new Azure.Identity.ManagedIdentityCredential(Environment.GetEnvironmentVariable("APP_IDENTITY_ID"));
var keyResolver = new Azure.Security.KeyVault.Keys.Cryptography.KeyResolver(credential);
var key = keyResolver.Resolve(new Uri(Environment.GetEnvironmentVariable("VAULT_KEY_URI")));
var encryptionOptions = new Azure.Storage.ClientSideEncryptionOptions(Azure.Storage.ClientSideEncryptionVersion.V1_0)
{
KeyEncryptionKey = key,
KeyResolver = keyResolver,
KeyWrapAlgorithm = Environment.GetEnvironmentVariable("VAULT_KEY_WRAP_ALGORITHM")
};
// get encrpyted blob client
var options = new Azure.Storage.Blobs.Specialized.SpecializedBlobClientOptions() { ClientSideEncryption = encryptionOptions };
var serviceClient = new Azure.Storage.Blobs.BlobServiceClient(connectionString, options);
var containerClient = serviceClient.GetBlobContainerClient("repro");
containerClient.CreateIfNotExists();
var blobClient = containerClient.GetBlobClient("repro");
// upload
await blobClient.UploadAsync(new BinaryData("TEST"), true);
Environment
Azure Function App (Windows, .NET 6) Visual Studio 2022
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to use "Azure storage blobs" for POST method in ...
How to get the local file path so I can pass on to the FileStream? You can use code like this: string localFilePath...
Read more >BlobClient.UploadAsync Method (Azure.Storage.Blobs)
The UploadAsync(BinaryData, BlobUploadOptions, CancellationToken) operation overwrites the contents of the blob, creating a new block blob if none exists.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I won’t get a chance to test the beta before the 14 day window closes. But I trust you. 😃
@davidjenkins I believe this has been fixed here - #26019
In the meantime, you can use the workaround mentioned in this comment.
@jaschrep-msft Could you share insights on when the next release of the SDK will be?