【发布时间】:2019-01-26 22:31:24
【问题描述】:
我正在使用 c#.net api 处理 azure 文件存储,但无法成功列出文件共享中的所有文件。我的代码错误:
Microsoft.WindowsAzure.Storage:服务器未能验证 要求。确保形成 Authorization 标头的值 正确包括签名。
以下代码完美运行,因此我与文件共享“temp”的连接很好:
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());
下面的代码导致所讨论的身份验证错误:
FileContinuationToken continuationToken = null;
do
{
var response = await share.GetRootDirectoryReference().ListFilesAndDirectoriesSegmentedAsync(continuationToken);
continuationToken = response.ContinuationToken;
}
while (continuationToken != null);
任何帮助将不胜感激。
谢谢。
【问题讨论】:
-
可以分享创建
fileClient的代码吗? -
谢谢。我已经更新了问题中的代码。
-
您的代码在我看来没问题。我能想到的 2 个原因会导致 403 错误:1)您的帐户密钥不正确,2)运行代码的计算机上的时钟运行缓慢(大约 15 分钟或更长时间)。你能检查一下这两件事吗?
-
我使用的是密钥 2,它适用于单个文件,但不适用于列出文件。我将其更改为键 1 并且它有效。感谢您的帮助!
标签: c# azure azure-storage fileshare