How Do I get the Name of The inputBlob That Triggered My Azure Function With Python

Viewed 2292

I have an azure function which is triggered by a file being put into blob storage and I was wondering how (if possible) to get the name of the blob (file) which triggered the function, I have tried doing:

fileObject=os.environ['inputBlob']
message = "Python script processed input blob'{0}'".format(fileObject.fileName)

and

fileObject=os.environ['inputBlob']
message = "Python script processed input blob'{0}'".format(fileObject.name)

but neither of these worked, they both resulted in errors. Can I get some help with this or some suggesstions?

Thanks

5 Answers

If you want to get the file name of the file that triggered your function you can to that:

Use {name} in function.json :

{
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "path": "MyBlobPath/{name}",
      "direction": "in",
      "connection": "MyStorageConnection"
    }
  ]
}

The function will be triggered by changes in yout blob storage.

Get the name of the file that triggered the function in python (init.py):

def main(myblob: func.InputStream):
    filemane = {myblob.name}

Will give you the name of the file that triggered your function.

Unfortunatelly it's still not possible. In Python, you can do:

import azure.functions as func
import os
def main(blobin: func.InputStream):
    filename=os.path.basename(blobin.name)
Related