繁体   English   中英

从Azure功能连接到Azure Blob存储

[英]Connecting to Azure Blob Storage from an Azure Function

我试图在我的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;
    }
}

编辑我应该提到此功能的部署版本正在Azure Dev / Test订阅上运行。 不确定这是否在这里发挥作用。 我将尝试部署到非开发订阅,看看它是否解决了任何问题。

因此,经过一些测试,看起来这是与Dev / Test订阅隔离的问题。 有点令人沮丧的是,我不得不把头撞到墙上一天来解决这个问题,但我想这就是游戏的名称。

希望这可以帮助其他人遇到这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM