Search code examples
c#azure-functionsinputbinding

How to read an XML file in a blob input binding with Azure Functions in C#?


I want to read an XML file from blob storage when my Azure Function is invoked with an Http trigger. How should I do this? I've looked at many different examples but none of them seem to work for me. The function works fine without the Blob input binding, but I want to read a file from blob storage every time it's invoked.

I've tried:

    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);
        }            

In the above code the Blob attribute is not understood by the VS2017 with error:

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

Solution

  • add a nuget package Microsoft.Azure.WebJobs.Extensions.Storage