编程语言
首页 > 编程语言> > c# – 使用HTTP触发器将Azure功能连接到Azure存储Blob

c# – 使用HTTP触发器将Azure功能连接到Azure存储Blob

作者:互联网

我遇到了将Azure存储Blob连接到Azure(like this one for example)函数的多种方法,但所有这些方法都要求我在Run函数中使用BlockBlob类型参数,因此替换了我需要的HTTPRequestMessage参数.有没有办法保持HTTPRequestMessage参数并连接到Azure存储Blob?

最终,我需要从blob获取文件引用,以通过Azure Function发送到另一个服务.

当我尝试向Run添加更多参数时,该函数编译正确,但我返回500错误.当我将参数更改回两个时,它可以正常工作.唯一的区别是参数和function.json我添加了一个部分,导致整个文件看起来像这样:

{
  "bindings": [
    {
      "authLevel": "function",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "blob",
      "name": "myBlobbo",
      "path": "mycontainer",
      "connection": "value",
      "direction": "inout"
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    }
  ],
  "disabled": false
}

//好吧,现在日志告诉我我没有指定连接字符串,即使我有一个local.settings.json文件,里面有这个:

{
  "ConnectionStrings": 
  {
    "xyz": "DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=yyy;EndpointSuffix=core.windows.net"
  }
}

我可能只是通过将URI传递给CloudBlobContainer并使用文件流或%TEMP%传递内容来手动连接,但我仍然非常想知道如何使这个绑定工作.

//我正在使用Azure环境来开发该功能.

解决方法:

以下示例显示了如何使用HttpRequest(HttpTrigger,Blob输入,Http out)获取blob内容:

run.csx

using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, string inputBlob, TraceWriter log)
{
    log.Info("Blob content: " + inputBlob);
    return req.CreateResponse(HttpStatusCode.OK, inputBlob);
}

functions.json

{
  "bindings": [
    {
      "authLevel": "function",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    },
    {
      "type": "blob",
      "name": "inputBlob",
      "path": "incontainer/myblob.txt",
      "connection": "AzureWebJobsDashboard",
      "direction": "in"
    }
  ],
  "disabled": false
}

存储:
enter image description here

AzureWebJobsDashboard:

enter image description here

标签:c,azure,azure-functions,azure-blob-storage
来源: https://codeday.me/bug/20190622/1263003.html