Reputation: 743
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
Upvotes: 0
Views: 994
Reputation: 743
Thanks to @Tom Sun - MSFT I have been sent to the right direction. I now compared all dependencies between the new ASP.Net Core app which I started from scratch and my actual solution.
The problem was the following package:
Microsoft.ApplicationInsights.AspNetCore
If I used the 2.1.0-beta I was faced with the error. Switching to the last stable 2.0.0 solved my problem
Upvotes: 0
Reputation: 24549
The MAC signature found in the HTTP request 'blankedOutKey' is not the same as any computed signature. Server used following string to sign: 'PUT'
According to the exception, it seems that construct authorization is not correct. But you are using Azure storage SDK. It seems that exception happened in the other code.
Please have a try to create a project and try it again. I can't repro it with you mentioned code in .net core Asp.net project. It works correctly on my side.
The following is my detail steps:
1.Create a .net core project.
2.Add the Azure storage SDK
3.Create the function with you mentioned code.
public async Task UploadBlobAsync()
{
const string myconnctionstring = "DefaultEndpointsProtocol=https;AccountName=accountname;AccountKey=yourkey;EndpointSuffix=core.windows.net";
//var storageAccount = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(myconnctionstring);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("test");
container.CreateIfNotExistsAsync().Wait();
// Retrieve reference to a blob named "test".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("test.jpg");
// Create or overwrite the "test" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"file path"))
{
await blockBlob.UploadFromStreamAsync(fileStream);
}
}
4.Call the function
public IActionResult About()
{
ViewData["Message"] = "upload blob.";
UploadBlobAsync().Wait();
return View();
}
5.Run the project and visit it about page, it works correctly.
6.I also catch it with fiddler.
Upvotes: 1