0

I have a Azure Function set up like this.

{
  "scriptFile": "identifier.py",
  "bindings": [
    {
      "name": "blob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "customers/{blob}",
      "connection": "DL_GEN2_STORAGE"
    }
  ]
}

The problem that I have is that the function triggers for folders as well as files, that are created in the blob storage.

Can one specify that it only triggers for files an not for folders?

torakaou
  • 185
  • 1
  • 13

2 Answers2

1

The problem you've got is that {blob} can't discern between folder or file as Azure Storage Blobs have no concept of directories. A directory in this sense is just part of the blob name.

You could filter on the blob name if a prefix is added to the file on upload but you're quite limited if you have no control over that.

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-trigger?tabs=in-process%2Cextensionv5&pivots=programming-language-python#blob-name-patterns

BrettMiller
  • 946
  • 2
  • 5
  • 12
  • yes, I thought about that, its unfortunate that this seems to be the only way – torakaou May 20 '22 at 10:51
  • I suppose the other alternative would be to consider how often a new "directory" would be created within the blob container and have your trigger as `"path": "input/{blobname}.{blobextension}",` and handle the error in that a directory wouldn't have a `blobextension`. It won't let you create a "directory" in the portal which contains a period but it will in something like storage explorer `https://teststorageacc9.blob.core.windows.net/testcontainer/folder1.folder2/parameters.json` which I'm not sure if it would be caught by the trigger `blobextension`. – BrettMiller May 20 '22 at 12:28
0

If anyone is interested. The problem that I had was that folders would throw errors when triggering the Azure function, because it was an unknown data type to the function. My current solution is to check the size of the blob.

def main(blob: func.InputStream):

    if blob.length is None:
        logging.info("The blob has no data in it.")
        logging.info("The blob is most likely a folder.")
        return

This way it does at least not throw an error when creating folders in the blob storage.

torakaou
  • 185
  • 1
  • 13