提问者:小点点

Python 中与 Azure Function 的 Blob 输入绑定不起作用(inputblob.name 为 None”)。如何排除故障?


我有以下用Python编写的简单Azure函数。它是一个 HTTP 触发器,应仅从 Azure 存储帐户返回 blob 输入绑定的名称和 URI(此处为 Microsoft 的参考文档)。

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}")

我的function.json文件是这样的。我已经验证了local.settings.json中的连接字符串是正确的,并且blob路径也是正确的。

{
  "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"
    }
  ]
}

现在,此函数返回“JSON名称:无。JSON URI:无”。显然blob输入绑定不起作用。如何对此进行故障排除,或者我遗漏了什么?


共1个答案

匿名用户

根据我的研究,目前,blob输入绑定的元数据(例如名称,长度)不是由函数主机提供的,但您仍然可以通过blob.read()访问blob绑定中的原始数据。有关更多详细信息,请参阅 https://github.com/Azure/azure-functions-python-worker/issues/576。

我的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"
    }
  ]
}

我的代码

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()}.")