Search code examples
azureazure-storageazure-blob-storageazure-functions

Azure Functions with blob storage. How to create a BlobTrigger to a sub-folder?


I need to react to a blob that's added into a sub-folder. I know that blob storage doesn't recognize the folders, they are just virtual, but I still can't figure out how to create a blob trigger if files are added to sub-folders.

Example:

Excerpt from function.json: { "name": "myblob", "type": "blobTrigger", "direction": "in", "path": "rootContainer/{name}" }

OK, a function is triggered and I receive the blob

Excerpt from function.json: { "name": "subfolder/myblob", "type": "blobTrigger", "direction": "in", "path": "rootContainer/{name}" } or { "name": "myblob", "type": "blobTrigger", "direction": "in", "path": "rootContainer/subfolder/{name}" }

NOT OK, a function isn't triggered

There are not many questions regarding this problem and they still don't provide a normal answer. Can't find any info in documentation either.

Thanks!


Solution

  • Shortly speaking, "path": "rootcontainer/subfolder/{name}" should work.

    Logs panel on function portal may not show logs in time, you can go to https://{functionappname}.scm.azurewebsites.net/DebugConsole, then navigate to D:\home\LogFiles\Application\Functions\function\yourblobtriggername to see log files.

    If you use blob name in your function code, path should include {name}, otherwise function won't run due to runtime exception.

    If you set path as a container like mycontainer or mycontainer/{name}, all files written to this container(including those uploaded to virtual subfolder) will trigger the function. As you have mentioned:

    it's fired when a root is rootcontainer, and blob which comes has the following name subfolder/{name}

    If you set it as a subfolder like mycontainer/subfolder/{name}, only files written to this subfolder will trigger the function.

    If set to mycontainer/subfolder, not triggered as you have found.

    Feel free to ask if you have further questions.