I'm trying to upload a image in Windows Azure Blob and I'm geting the following error which I can't handle.
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
The error occurs when I try to create a container.
container.CreateIfNotExists()
Here is my code
try
{
Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference("samples");
// Create the container if it doesn't already exist.
//here is the error
if (container.CreateIfNotExists())
{
container.SetPermissions(
new BlobContainerPermissions
{
PublicAccess =
BlobContainerPublicAccessType.Blob
});
}
CloudBlockBlob blockBlob = container.GetBlockBlobReference("Image1");
using (var fileStream = System.IO.File.OpenRead(@"Path"))
{
blockBlob.UploadFromStream(fileStream);
}
}
catch (StorageException ex1)
{
throw ex1;
}
I have tryied a lot of options in my code but still getting the error.
Anyone can please help me? Thanks.
My PC's time was off by 1 hour as suggested by others in the comments. Correcting it solved the problem.
I got this message when I was trying to access BLOB Storage through REST API Endpoint.
Below is the response that I got when invoked list container operation with Authorization header
<?xml version="1.0" encoding="utf-8"?>
<Error>
<Code>AuthenticationFailed</Code>
<Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:096c6d73-f01e-0054-6816-e8eaed000000
Time:2019-03-31T23:08:43.6593937Z</Message>
<AuthenticationErrorDetail>Authentication scheme Bearer is not supported in this version.</AuthenticationErrorDetail>
</Error>
solution was to include below header
x-ms-version: 2017-11-09
in my case it was actually the shared access signature (SAS) that expired. updating (actually making a new one) the shared access signature in portal.azure.com by adding a year (or more) for end date in the future. And all problems fixed.
Check the timezone of your computer or mobile phone.
In my case I was passing storage connection string with access signature as an argument to console application. '%' in command line is an special character 'command line parameters'. '%' appears in access signature (SAS). You have to escape percent %, double it %%.
来源:https://stackoverflow.com/questions/24492790/azurestorage-blob-server-failed-to-authenticate-the-request-make-sure-the-value