Hi,
I am using Microsoft.WindowsAzure.Storage (Azure Storage SDK for Windows) version : 9.3.2.0 for uploading the blob.
Here is logic of c# code for the same.
private class FileBlock
{
internal string Id { get; set; }
internal byte[] Content { get; set; }
}
public static async Task<Uri> UploadFileToAzureStorageAsync(string azureStorageUri, string filePath)
{
var bytes = File.ReadAllBytes(filePath);
var cloudBlockBlob = new CloudBlockBlob(new Uri(azureStorageUri));
var blocks = new HashSet<string>();
try
{
foreach (var block in GetFileBlocks(bytes))
{
cloudBlockBlob.PutBlock(block.Id, new MemoryStream(block.Content, true), null);
blocks.Add(block.Id);
}
await cloudBlockBlob.PutBlockListAsync(blocks);
}
catch (Exception ex)
{
Logging.logger.Error(ex);
}
return cloudBlockBlob.Uri;
}
private static IEnumerable<FileBlock> GetFileBlocks(byte[] fileContent)
{
if (fileContent.Length == 0)
return new HashSet<FileBlock>();
var maxBlockSize = 4 * 1024 * 1024;
var hashSet = new HashSet<FileBlock>();
var blockId = 0;
var index = 0;
var currentBlockSize = maxBlockSize;
while (currentBlockSize == maxBlockSize)
{
if ((index + currentBlockSize) > fileContent.Length)
currentBlockSize = fileContent.Length - index;
var chunk = new byte[currentBlockSize];
Array.Copy(fileContent, index, chunk, 0, currentBlockSize);
hashSet.Add(new FileBlock
{
Content = chunk,
Id = Convert.ToBase64String(BitConverter.GetBytes(blockId))
});
index += currentBlockSize;
blockId++;
}
return hashSet;
}
I am seeing this issue intermittently for few packages. If i publish again it will be successful. I read few blogs which suggest to change machine to UTC time zone. I tried that as well but still the same error occurs as shown below.
I wanted to know if there is issue for the below exception.
Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (403) Forbidden.
---> System.Net.WebException: The remote server returned an error: (403) Forbidden.
StatusMessage:Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
ErrorCode:AuthenticationFailed
ErrorMessage:Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
Thanks,
Sangamesh