3

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.

Dan Young
  • 137
  • 1
  • 2
  • 12
  • Can you share the code for creating `fileClient`? – Gaurav Mantri Aug 20 '18 at 18:51
  • Thanks. I've updated the code in the question. – Dan Young Aug 20 '18 at 19:34
  • 1
    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 Aug 20 '18 at 20:06
  • 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 Aug 20 '18 at 20:37

1 Answers1

0

Using key 1 instead of key resolved the issue.

Dan Young
  • 137
  • 1
  • 2
  • 12