1
votes

I have the following simple Azure Function written in Python. It is an HTTP trigger that should simply return the name and URI of the blob input binding from an Azure storage account (reference documentation from Microsoft here).

import logging
import azure.functions as func
import azure.storage.blob
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient

def main(req: func.HttpRequest, inputblob: func.InputStream) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    return func.HttpResponse(f"Blob name: {inputblob.name}. Blob URI: {inputblob.uri}")

My function.json file looks like this. I've verified that the connection string in local.settings.json is correct and that the blob path is correct too.

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "name": "inputblob",
      "type": "blob",
      "path": "containername/testblobname.json",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "in"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

Now, this function returns "JSON name: None. JSON URI: None". Clearly the blob input binding is not working. How do I troubleshoot this, or what am I missing?

1

1 Answers

6
votes

According to my research, at the moment, the metadata of the blob input binding (e.g. name, length) is not provided by the function host, but you can still access the raw data in blob binding via blob.read(). For more details, please refer to https://github.com/Azure/azure-functions-python-worker/issues/576.

My function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "name": "inputblob",
      "type": "blob",
      "path": "input/keyCredentials.txt",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "in"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

My code

import logging

import azure.functions as func


def main(req: func.HttpRequest, inputblob: func.InputStream) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    return func.HttpResponse(f"Blob conetnt: {inputblob.read()}.")