【问题标题】:How do I create an Azure API that connects to my Blob Storage?如何创建连接到我的 Blob 存储的 Azure API?
【发布时间】:2021-11-23 23:25:27
【问题描述】:

所以我创建了一个函数应用程序,现在我正在尝试创建一个连接到我的 Blob 存储并“发布”容器内的内容的 API


import azure.functions as func


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

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )

【问题讨论】:

  • 不确定您的问题是什么。请编辑您的问题,详细说明您正在尝试做什么以及遇到的问题。除非您能够解释您的问题,否则很遗憾,社区很难(或不可能)为您提供帮助。
  • 你的函数看起来像一个简单的http触发函数。没有尝试连接并写入 blob 存储的代码。您是否参考过使用输出绑定写入 blob 存储的文档 docs.microsoft.com/en-us/azure/azure-functions/…

标签: python azure http azure-functions azure-http-trigger


【解决方案1】:

谢谢Anupam Chand。发布您的建议作为帮助其他社区成员的答案。

输出绑定允许您使用 azure 函数连接到 blob 存储。

以下是如何使用输出和输入绑定连接到 Blob 存储的示例代码。

{
  "bindings": [
    {
      "queueName": "myqueue-items",
      "connection": "MyStorageConnectionAppSetting",
      "name": "queuemsg",
      "type": "queueTrigger",
      "direction": "in"
    },
    {
      "name": "inputblob",
      "type": "blob",
      "dataType": "binary",
      "path": "samples-workitems/{queueTrigger}",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "in"
    },
    {
      "name": "outputblob",
      "type": "blob",
      "dataType": "binary",
      "path": "samples-workitems/{queueTrigger}-Copy",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "out"
    }
  ],
  "disabled": false,
  "scriptFile": "__init__.py"
}

相关信息请查看Azure Blob output bindings

【讨论】:

    猜你喜欢
    • 2022-08-03
    • 2021-11-25
    • 1970-01-01
    • 2014-04-25
    • 2015-05-29
    • 1970-01-01
    • 2021-07-11
    • 2017-09-17
    • 1970-01-01
    相关资源
    最近更新 更多