gwo*_*984 6 c# azure azure-storage azure-storage-blobs azure-functions
我正在尝试在我的 v2 函数应用程序中使用CloudBlobClient c# 类从存储在 Azure Blob 存储上的文件中读取数据。在本地运行时,我的代码能够拉回数据,但是当使用相同的连接字符串和我的代码调用部署代码时GetBlobReferenceFromServerAsync,我收到以下错误:
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
我从存储帐户 > 访问密钥 > Key1 的连接字符串中获取了连接字符串,其格式如下:
DefaultEndpointsProtocol=https;AccountName=<AccountName>;AccountKey=<AccountKey>;EndpointSuffix=core.windows.net
我曾尝试授予应用服务帐户所有者访问存储帐户的权限并尝试使用共享访问签名,但到目前为止没有任何效果。是否需要在函数应用或存储帐户端应用某些权限才能使此功能正常工作?
下面是代码的一个片段:
var storageConnectionString = blobConfig.ConnectionString;
if (CloudStorageAccount.TryParse(storageConnectionString, out var storageAccount))
{
try
{
// Create the CloudBlobClient that represents the Blob storage endpoint for the storage account.
var cloudBlobClient = storageAccount.CreateCloudBlobClient();
var container = cloudBlobClient.GetContainerReference(containerName);
var uri = new Uri(cloudBlobClient.BaseUri, $"/{containerName}{path}");
// get the blob object and download to file
// ---- THROWS ON NEXT LINE ----
var blobRef = await cloudBlobClient.GetBlobReferenceFromServerAsync(uri);
var tempFilePath = System.IO.Path.GetTempFileName();
await blobRef.DownloadToFileAsync(tempFilePath, System.IO.FileMode.Truncate);
return tempFilePath;
}
catch (StorageException ex)
{
log.LogError(ex, "Error returned from the service: {0}", ex.Message);
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑 我应该提到此功能的已部署版本正在 Azure 开发/测试订阅上运行。不确定这是否在这里起作用。我将尝试部署到非开发订阅,看看它是否能解决任何问题。
因此,经过一些测试后,看来这是一个与开发/测试订阅无关的问题。有点令人沮丧的是,我不得不用头撞墙一天才能弄清楚这一点,但我想这就是游戏的名称。
希望这可以帮助其他人解决这个问题。
| 归档时间: |
|
| 查看次数: |
3876 次 |
| 最近记录: |