如何使用C#中的Azure函数读取Blob输入绑定中的XML文件?

时间:2019-01-05 11:44:53

标签: c# azure-functions inputbinding

当我使用Http触发器调用Azure函数时,我想从blob存储中读取XML文件。我应该怎么做?我看过许多不同的示例,但似乎没有一个适合我。该功能在没有Blob输入绑定的情况下可以正常工作,但是我希望每次调用时从Blob存储中读取文件。

我尝试过:

    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
        [Blob("config/log4netConfig.xml", FileAccess.Read)] Stream configFile,            
        ILogger log)
    {
        XmlDocument doc = new XmlDocument();
        using (XmlReader reader = XmlReader.Create(configFile))
        {
            doc.Load(reader);
        }            

在上面的代码中,VS2017无法理解Blob属性,并出现错误:

Error CS0246 The type or namespace name 'BlobAttribute' could not be found (are you missing a using directive or an assembly reference?)

1 个答案:

答案 0 :(得分:1)

添加一个nuget包 Microsoft.Azure.WebJobs.Extensions.Storage