2
votes

I am using the c#.net api to work with azure file storage but cannot successfully list all files in a fileshare. My code errors with:

Microsoft.WindowsAzure.Storage: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.

The following code works perfectly, so my connection to the fileshare 'temp' is fine:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();   
CloudFileShare share = fileClient.GetShareReference("temp");
CloudFile f = share.GetRootDirectoryReference().GetFileReference("Report-461fab0e-068e-42f0-b480-c5744272e103-8-14-2018.pdf");  
log.Info("size " + f.StreamMinimumReadSizeInBytes.ToString());

The code below results in the discussed authentication error:

FileContinuationToken continuationToken = null;
do
{
    var response = await share.GetRootDirectoryReference().ListFilesAndDirectoriesSegmentedAsync(continuationToken);
    continuationToken = response.ContinuationToken;
}
while (continuationToken != null);

Any help would be appreciated.

Thanks.

1
Can you share the code for creating fileClient?Gaurav Mantri
Thanks. I've updated the code in the question.Dan Young
Your code looks OK to me. 2 reasons I could think of would cause 403 error: 1) Your account key is incorrect and 2) The clock on the computer where your code is running is running slow (by approximately 15 minutes or more). Can you please check for these 2 things?Gaurav Mantri
I was using key 2 which worked for individual files but not for listing files. I changed it to key 1 and it worked. Thanks for your help!Dan Young

1 Answers

0
votes

Using key 1 instead of key resolved the issue.