2

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)
Dave
  • 454
  • 1
  • 7
  • 17
  • This should works fine, any error you get? – Cindy Pau Feb 10 '21 at 01:32
  • I don't get any errors, other than those encountered later because the files are the same. Mind you, I've only been testing locally, and when asked for a body I get the path to a known file eg. "path1/data.xlsx", which works pulling in just that file – Dave Feb 10 '21 at 01:34
  • Can you show the code structure? – Cindy Pau Feb 10 '21 at 01:35
  • I've added more code above to the init.py file example. There are a few definitions in there and some imports but otherwise, that's it. – Dave Feb 10 '21 at 01:39
  • I think for the metadata, azure binding of python still has some problems for the time being. In fact, what you input is indeed two different blob objects, but the input part cannot get metadata values like uri and so on. – Cindy Pau Feb 10 '21 at 02:25

1 Answers1

2

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.

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • Thank you bowman! This makes sense - although it's strange that they haven't fixed this... I then try to read the file into pd.read_excel, and the decode('utf-8') gives me an error: `UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 16: invalid continuation byte` Is this a blob issue, or an issue with the data coming through? – Dave Feb 10 '21 at 02:52
  • @Dave Are you using panda? I'm not sure, it looks like the decoding way is wrong (just a guess), you can google it or ask a question on SO. – Cindy Pau Feb 10 '21 at 02:56
  • 1
    Yeah using pd.read_excel() through pandas. Okay no worries, thanks for your help!! – Dave Feb 10 '21 at 03:08