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

时间:2018-02-16 09:46:30

标签: c# azure azure-functions azure-blob-storage

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

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

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

where Id = $id and a !=$a
   Or (state = $state and (b !=b or c!= $c))

//好吧,现在日志告诉我,我没有指定连接字符串,即使我有一个local.settings.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
}

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

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

1 个答案:

答案 0 :(得分:5)

以下示例显示了如何使用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