1

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 Answer 1

6

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()}.")
Sign up to request clarification or add additional context in comments.

2 Comments

I get an error saying "The binding type(s) 'blob' are not registered. Please ensure the type is correct and the binding extension is installed." Any ideas?
@RajatArora, please try to add the following code in the host.json "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[1.*, 2.0.0)" }

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.