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)
5
  • This should works fine, any error you get? Commented Feb 10, 2021 at 1: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 Commented Feb 10, 2021 at 1:34
  • Can you show the code structure? Commented Feb 10, 2021 at 1: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. Commented Feb 10, 2021 at 1: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. Commented Feb 10, 2021 at 2:25

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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 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.
Yeah using pd.read_excel() through pandas. Okay no worries, thanks for your help!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.