Input multiple blobs into azure function python

Viewed 365

I'm working in python for a Azure function. I am trying to read in two blobs, one that is triggered, and a static blob.

When I read them in, both blobs point to the triggered blob (URI is the same). How can input and use two blobs correctly?

My bindings look like:

{
      "name": "techdatablob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "path1/{name}",
      "connection": "example"
    },
    {
      "name": "crmdatablob",
      "type": "blob",
      "direction": "in",
      "path": "path2/data.xlsx",
      "connection": "example"
    },
    {
      "name": "outputblob",
      "type": "blob",
      "direction": "out",
      "path": "path3/out.xlsx",
      "connection": "example"
    }

And the init.py file starts with:

def main(techdatablob: func.InputStream, crmdatablob: func.InputStream, outputblob: func.Out[func.InputStream]):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {techdatablob.name}\n"
                 f"Blob Size: {techdatablob.length} bytes")

    print(techdatablob.uri)
    print(crmdatablob.uri)
1 Answers

When I read them in, both blobs point to the triggered blob (URI is the same). How can input and use two blobs correctly?

In fact, you have already input the multiple blob, the problem comes from azure function blob binding metadata is not from the function host, so things such as blob name, blob length, uri etc cannot get correct values. But in fact their data is different (the objects are also different).

You can do something like below to test:

import logging

import azure.functions as func


def main(techdatablob: func.InputStream, crmdatablob: func.InputStream) -> None:
    logging.info("-----"+techdatablob.read().decode('utf-8'))
    logging.info("-----"+crmdatablob.read().decode('utf-8'))

Have a check of this error page:

https://github.com/Azure/azure-functions-python-worker/issues/576

I think the problem is not on your side, it is a function design problem. There should be no problem using storage sdk to get metadata.

Related