From my ASP.Net Core app, I try to upload a block blob to Azure Storage Service. I took the example from Microsoft:
var accountName = "accountname";
var accountKey = "key";
//var storageAccount = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("myconnectionstring");
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference(Container);
// Retrieve reference to a blob named "test".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("test");
// Create or overwrite the "test" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"E:\Drone\N_01004619000008.jpg"))
{
await blockBlob.UploadFromStreamAsync(fileStream);
}
This results in the following error:
StorageException: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
Using fiddler I could also see this additional error info:
The MAC signature found in the HTTP request 'blankedOutKey' is not the same as any computed signature. Server used following string to sign: 'PUT'
...whereas the 'blankedOutKey' is not the key I actually used for authentication. Not sure where it comes from. As you can see in my Code Snippet, I tried both using my accountName and accountKey as well as the ConnectionString.
What am I doing wrong?
Edit: I tried this here: https://github.com/Azure-Samples/storage-dotnet-sas-getting-started
With the exact same connection string, it worked in the solution from github but when I took over the complete code to my ASP.Net Core 1.1 app, I again faced the issue mentioned. So I double checked the differences. It turns out that the project from github uses the 6.2.0 version of "Microsoft.WindowsAzure.Storage" while my ASP.Net Core app uses the 8.1.3 version.
Furthermore, I double checked the HTTP requests from both solutions in fiddler. Here is the one from the older SDK which works:
User-Agent: WA-Storage/6.2.0 (.NET CLR 4.0.30319.42000; Win32NT 6.2.9200.0) x-ms-version: 2015-04-05 x-ms-client-request-id: c1aea889-73f8-4b6b-9a1f-2f2f9e021846 x-ms-date: Sun, 04 Jun 2017 12:23:37 GMT Authorization: SharedKey mystoragename:F5yhOOh2taUBfUE+3wii1cYb0D7L+jZGVfs1xTgTme0= Host: mystoragename.blob.core.windows.net Content-Length: 0
The request submitted through the newer SDK which fails:
Connection: Keep-Alive Authorization: SharedKey mystoragenamee:IxtXuZFIcPjeKnqjktxvfcQMRLkfHM5SVN9zvQZmBJc= User-Agent: Azure-Storage/8.1.3 (.NET Core) x-ms-client-request-id: d890d2e0-07af-4695-af1f-8020c9476774 x-ms-version: 2016-05-31 x-ms-date: Sun, 04 Jun 2017 12:24:49 GMT x-ms-request-root-id: 428e8e6279f1ff9d-4237b4f7 x-ms-request-id: |428e8e6279f1ff9d-4237b4f7.1. Request-Id: |428e8e6279f1ff9d-4237b4f7.1. Content-Length: 0 Host: mystoragename.blob.core.windows.net