How do I get the name of the input blob of my Azure WebJob?

做~自己de王妃 提交于 2020-01-04 14:28:52

问题


I'm using the new Azure WebJobs feature and have a simple trigger when a new file comes into one of by blobs:

public static void ProcessImportFile([BlobInput("importjobsdata/{name}")] TextReader input,
                                    [BlobOutput("importjobslog/log_{name}")] TextWriter writer)
{
    writer.WriteLine("Starting import file process...");

    var result = InputData(input, writer);

    var status = result == 0 ? "SUCCESS" : "FAIL";
    var message = result == 0
        ? "Import success."
        : "Import fail. " + result + " records failed to import. Check logs for details.";

    writer.WriteLine(message);
}

What I'd like to do is get the name of the file that was uploaded (ie. the {name} property in the data annotation) so that I can write that information to the writer (log) for diagnostic purposes.

However, I can't seem to find any properties of the TextReader/BlobInput that will give me this information.

I've done a little digging and it appears that the BaseStream property of the TextReader is a Microsoft.WindowsAzure.Jobs.WatchableStream object. I'm not sure if this helps track down the name or not.

How do I go about getting it?


回答1:


the value of the name capture would be passed to arguments with that name as well. So you should be able to do that:

public static void ProcessImportFile([BlobInput("importjobsdata/{name}")] TextReader input,
                                     string name,
                                     [BlobOutput("importjobslog/log_{name}")] TextWriter writer)
{
    writer.WriteLine(name);
}


来源:https://stackoverflow.com/questions/22873823/how-do-i-get-the-name-of-the-input-blob-of-my-azure-webjob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!