Search code examples
pythonazure-functionsazure-blob-storageazure-blob-trigger

Azure function blob trigger blob paratemer error


I am using a blob trigger to read the blob contents, process as a pandas DF and append the blob to the Azure SQL server I am using.

The blob trigger didn't work as expected so I defined all code in the main function as such:

def main(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")
    file = re.sub(r'^(.*?)\/','',myblob.name)
    if file not in processedfiles:
        stream = BytesIO((myblob.read()))
        stream.seek(0)

However I get the following error:

Exception: FunctionLoadError: cannot load the BlobFileTrigger function: 
binding myblob has invalid non-type annotation <sqlalchemy.sql.functions._FunctionGenerator object at 0x7faa340f6a00>

Can someone help me find the cause of this issue?

The function.json is configured as follows:

{
  "scriptFile": "__init__.py",
  "disabled": false,
  "bindings": [
      {
          "name": "myblob",
          "type": "blobTrigger",
          "direction": "in",
          "path": "input/{name}",
          "connection":"StorageConnection"
      }
  ]
}

Solution

    • The configured function.json file is fine.

    • If you are getting an empty byte string, so use the seek(0) method first then Read() from stream.

    • Make sure that if condition is proper on the processedfiles, because if it's not found any files in processedfiles then only your case will execute.

      i.e.:- stream = BytesIO((myblob.read()))

    Reference: read() and getvalue() methods of Python io.BytesIO

    Azure Functions with Blobtrigger in Python