0

So I have created a function app and now I am trying to create an API that connects to my Blob Storage and "Posts" the content within the container


import azure.functions as func


def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )
noobdev123
  • 51
  • 7
  • Not sure what your question is here. Please edit your question elaborate what you're trying to do and the issues you're running into. Unless you are able to explain your problem, unfortunately it will be very hard (or impossible) for the community to help you out. – Gaurav Mantri Oct 03 '21 at 02:27
  • Your function looks like a simple http trigger function. There is no code which attempts to connect and write into the blob storage. Have you referred to the documentation https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-output?tabs=python which uses output bindings to write to blob stores? – Anupam Chand Oct 04 '21 at 01:04

1 Answers1

0

Thank you Anupam Chand. Posting your suggestions as an answer to help other community members.

The Output Binding allows you to connect to the blob storage using azure function.

Below is the sample code in how to connect to the Blob storage using output and input bindings.

{
  "bindings": [
    {
      "queueName": "myqueue-items",
      "connection": "MyStorageConnectionAppSetting",
      "name": "queuemsg",
      "type": "queueTrigger",
      "direction": "in"
    },
    {
      "name": "inputblob",
      "type": "blob",
      "dataType": "binary",
      "path": "samples-workitems/{queueTrigger}",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "in"
    },
    {
      "name": "outputblob",
      "type": "blob",
      "dataType": "binary",
      "path": "samples-workitems/{queueTrigger}-Copy",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "out"
    }
  ],
  "disabled": false,
  "scriptFile": "__init__.py"
}

For related information check Azure Blob output bindings.

SaiSakethGuduru
  • 2,218
  • 1
  • 5
  • 15