azureazure-webjobsazure-webjobssdkazure-webjobs-triggered

How to get FileTrigger to work with Azure file storage in Webjob


I have a webjob that I have set up to be triggered when a file is added to a directory:

[FileTrigger(@"<DIR>\<dir>\{name}", "*", WatcherChangeTypes.Created, autoDelete: true)] Stream file,

I have it configured:

var config = new JobHostConfiguration
                {
                    JobActivator = new NinjectActivator(kernel)
                };
                var filesConfig = new FilesConfiguration();
#if DEBUG
                filesConfig.RootPath = @"C:\Temp\";
#endif
                config.UseFiles(filesConfig);
                config.UseCore();

The path is for working locally and I was expecting that commenting out the FilesConfiguration object leaving it default would allow it to pick up the connection string I have set up and trigger when files are added. This does not happen it turns out that by default the RootPath is set to "D:\Home" and produces an InvalidOperationException

System.InvalidOperationException : Path 'D:\home\data\<DIR>\<dir>' does not exist.

How do I get the trigger to point at the File storage area of the storage account I have set up for it. I have tried removing the FilesConfiguration completely from Program.cs in the hope that it would work against the settings but it only produces the same Exception.


Solution

  • System.InvalidOperationException : Path 'D:\home\data\\' does not exist.

    When you publish to azure, the default directory is D:\HOME\DATA, so when you run webjob it could not find the path so you get the error message.

    How do I get the trigger to point at the File storage area of the storage account I have set up for it.

    The connectionstring you have set have two applies: one is used for dashboard logging and the other is used for application functionality (queues, tables, blobs).

    It seems that you could not get filetrigger working with azure file storage. So, if you want to invoke your filetrigger when you create new file, you could go to D:\home\data\ in KUDU to create a DIR folder and then create new .txt file in it.

    The output is as below:

    enter image description here

    BTW, it seems that you'd better not use autoDelete when you create file, if use you will get error like:

    NotSupportedException: Use of AutoDelete is not supported when using change type 'Changed'.