1
votes

Hi I have created a azure function httptrigger to read a blob from blob storage with blob input bindings.

below is the function.json:

{
  "disabled": false,
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req"
    },
    {
      "name" : "blobContent",
      "type": "blob",
      "direction": "in",
      "path": "containerName/{id}.{extn}",
       "connection": "AzureWebJobsStorage"
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    }
  ]
}

and the index.js file is :

module.exports = function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    if (req.query.id || (req.body && req.body.id)) {   
        context.res = {
            body : {'data' : context.bindings.blobContent},
            headers : {'Content-type': 'application/xml"'}
        }
    }
    else {
        context.res = {
            status: 400,
            body: "Please pass a object/chuck id on the query string or in the request body"
        };
    }
    context.done(null,context.res);
};

I am using both get and post method to call the httptrigger. Since i am using blob input binding, the content is retrieved before processing index.js. With this, i couldn't validate whether the API called with id and extn. Is there a way to handle the exception and give a message back to the API caller to pass the necessary parameters. Thanks in advance.

1
You can always use the blob client from Azure Storage SDK, if you pass the blob name in the HTTP payload that is (read request body --> your custom logic --> blob client --> fetch blob and return)evilSnobu
Thank you for the information. Is there any performance difference between using Azure SDK vs binding?Siva SM
No. Uses the same SDK behind the scenes. It's about convinience not performance. There's some gRPC involved between the host and language worker but in most cases that's very little overhead. So if anything, using the storage SDK directly should be a little faster but only marginally.evilSnobu
Thank you for the valuable information. Appreciate that..Siva SM

1 Answers

3
votes

So Functions does have some way of doing this, called Function Filters. This feature allows you to write methods that are called before or after the job function is ran (Invocation Filters), or that are invoked whenever the code encounters an exception in the functions runtime (Exception Filters). You could write an exception filter that catches an exception when the input binding fails and that would accomplish what you want.

Unfortunately, at the time of writing this answer, Function Filters are only compatible with pre-compiled C# functions. There is currently this issue tracking this feature's addition into other scenarios.