6
votes

I came across multiple ways of connecting Azure Storage Blobs to Azure (like this one for example) Functions but all of them require me to use a BlockBlob type parameter in my Run function, therefore replacing the HTTPRequestMessage parameter I need. Is there a way to keep the HTTPRequestMessage parameter and connect to Azure Storage Blob?

Ultimately, I need to get a file reference from the blob to send to another service via Azure Function.

When I try to add more parameters to Run, the function compiles properly, but I am returned a 500 error. When I change the parameters back to two, it works properly. The only difference is the parameter and function.json to which I add a section resulting in the entire file looking like this :

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

// Alright, now the logs are telling me that I didn't specify a connection string, even though I have a local.settings.json file with this inside:

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

I'm probably going to just connect manually via passing an URI to CloudBlobContainer and using a file stream or %TEMP% to pass the contents, but I still would very much like to know how to get this binding to work.

// I'm using Azure environment to develop the function.

1
Are you using azure portal or Visual Studio to develop your function? bindings.json looks like you are using portal but local.settings.json used for Visual Studio.Alexey Rodionov
I'm using Azure Portal. I added a new file called local.settings.json to my function and added the contents shown in the thread (the ConnectionStrings part) to it.user8620003
I am also finding it really hard to take the toy examples of an HTTP request and extend it to simply read a blob container's contents out using a foreach. Iterating over the standard file store should be really easy, but it is turning out to be really hard.John Drinane

1 Answers

6
votes

Following example shows how to get blob content with HttpRequest (HttpTrigger, Blob input, Http out):

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
}

storage: enter image description here

AzureWebJobsDashboard:

enter image description here