I'm trying to upload a file in Azure by using a SAS token but I receive this error while I try to upload the file :
MD5 is not a known hash algorithm
I have these 2 methods that I use, one to generate the file link which will be used to upload the file:
public string GetBlobSASUploadFileLink(string fileName)
{
var connectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", StorageAccountName, AccessKey);
var storageAccount = CloudStorageAccount.Parse(connectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(FilesContainer);
SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(5);
sasConstraints.Permissions = SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create;
var blob = container.GetBlockBlobReference(fileName);
return string.Format("{0}{1}", blob.Uri, blob.GetSharedAccessSignature(sasConstraints));
}
And this method where also the exception is thrown, which should upload the file in Azure:
public async Task UploadFilesToBlob(string fileLink, IBrowserFile file)
{
try
{
var cloudBlockBlob = new CloudBlockBlob(new Uri(fileLink));
await cloudBlockBlob.UploadFromStreamAsync(file.OpenReadStream(912000000));
}
catch (Exception ex)
{
}
}
In this second method in the UploadFromStreamAsync
method the exception is thrown.
I'm guessing the framework uses the MD5 algorithm but the Azure uses another cryptographic hashing algorithm but I don't know what should be done.
I follow the official sample code and test it, it works fine. You can refer my test code.
Test Result:
Sample code like below: