how to use an http triggered function with blob input?

javier 946 Reputation points
2020-12-02T19:23:27.883+00:00

I'm making an post request to a azure http triggered function but getting an error about httpTrigger not found

The body contains the blob name and some other value:
{
"filename" : "customers.csv",
"foo" : False
}

my function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
{
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    }, 
{
      "name": "inputblob",
      "type": "blob",
      "path": "suplaitransferin/{httpTrigger}",
      "connection": "suplaitransferin_STORAGE",
      "direction": "in"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

if I replace {httpTrigger} by a fixed string (like 'customers.csv'), it works.

I am aware of the fact that the body has two properties and I not specifying in the function.json which one is the actual blob name.

So my question is, how do I get the function to recognize the blob name specified in the body of the request?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
0 comments No comments
{count} votes

Answer accepted by question author
  1. MayankBargali-MSFT 70,986 Reputation points Moderator
    2020-12-03T04:10:52.177+00:00

    Hi @javier

    You cannot use the HTTP request body and passed the value to the input binding for the blob. The alternative way would be passing a parameter to HTTP request and then use that parameter in the path of your blob input bindings.

    Please note that if the blob name is passed incorrectly (blob doesn't exist) in the parameter of HTTP request then your function will not execute as you would have defined your function as to take InputStream or other supported value which will fail.

    HTTP Request URL : http://{yourfunctionapp}/api/HttpTrigger1?blobname=test.txt

    In the above, if test.txt is not in the container input for the configured storage account then your function will fail as mentioned above.

    def main(req: func.HttpRequest, inputblob: func.InputStream) -> func.HttpResponse:

    {  
      "scriptFile": "__init__.py",  
      "bindings": [  
        {  
          "authLevel": "anonymous",  
          "type": "httpTrigger",  
          "direction": "in",  
          "name": "req",  
          "methods": [  
            "get",  
            "post"  
          ]  
        },  
        {  
          "name": "inputblob",  
          "type": "blob",  
          "path": "input/{blobname}",  
          "connection": "AzureWebJobsStorage",  
          "direction": "in"  
        },  
        {  
          "type": "http",  
          "direction": "out",  
          "name": "$return"  
        }  
      ]  
    }  
    

    If this works with you then you can go with this approach but the function will always return 500 error if the inputs blob name is not correct.
    The alternative you can only use HTTP input binding and based on HTTP body input you need to write your own code to communicate with storage services.

    Please let me know if you have any queries or concerns.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.