Reputation: 131
enter code here
I am trying to download the file stored in azure blob using javascript and getting this error.
Here is my code
function getUrlOfAttachmentFileFromBlob(new_fileurl,new_fileName) {
var fileHyperlink = '';
var blobUri = 'https://' + 'Storage_Account_Name' + '.blob.core.windows.net';
var containerName = 'trial';
var sas_token = 'sastoken' ;
var blobService = AzureStorage.Blob.createBlobServiceWithSas(blobUri, sas_token);
//.withFilter(new AzureStorage.Blob.ExponentialRetryPolicyFilter());
var downloadLink = blobService.getUrl(new_fileName, new_fileurl.replace('/'+containerName+'/',''), sas_token);
if (downloadLink != null)
{
alert("Link " + downloadLink);
downloadURI(downloadLink, new_fileName);
}
}
I am not generating shared signature and sas token here. I am directly assigning the sas token to the variable.
When I try to open the link in browser I am getting this error
AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:504f2ef5-f01e-0021-0e02-74e194000000
Time:2021-07-08T14:09:47.9951927Z</Message><AuthenticationErrorDetail>sp is mandatory. Cannot be empty</AuthenticationErrorDetail></Error>
I am not passing any headers in my code.
What i am missing here?
SAS Token = ?sp=r&st=2021-07-08T12:19:08Z&se=2021-07-08T20:19:08Z&spr=https&sv=2020-02-10&sr=c&
Without sig part.
This is what I am getting from geturl function =
?%3Fsv=2020-02-10&ss=bfqt&srt=sco&sp=rwdlacuptfx&se=2021-07-11T12%3A30%3A23Z&st=2021-06-11T04%3A30%3A23Z&spr=https%2chttp&
I think I am not getting correct url from this function, so i replaced that line with this
const downloadLink = blobUri +'/' + containerName + '/' + new_fileName + sas_token;
But still not able to download the file. But not getting authentication error.
Thank you...
Upvotes: 3
Views: 27710
Reputation: 70
For me I was using the incorrect PowerShell cmdlet to create the SAS token in the first place, hence why I was always getting Authorization error in my AZCOPY command
I was using: New-AzStorageFileSASToken
cmdlet
Changing to use: New-AzStorageShareSASToken
cmdlet resolved the auth issues for me.
Original error:
Description=Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature
Upvotes: 0
Reputation: 11
I resolve the related issues on shared access signature (SAS) Allowed resource types by clicking Service
Container
Object and finally generate new token works fine.
Upvotes: 1
Reputation: 136146
The reason you're getting this error is because your SAS token is not valid. If you look closely at the error message you will see the following:
<AuthenticationErrorDetail>sp is mandatory. Cannot be empty</AuthenticationErrorDetail>
Essentially your SAS token is missing signed permissions (sp)
parameter. Please check your SAS token and make sure that it is correctly formed.
Upvotes: 2