简体   繁体   中英

How to dynamically read blob file from Azure Function Python

I want to be able to dynamically read the blob file (json) with Azure Function Python with the filename passed through Azure Event hub message. How can I do that with Azure Bindings?

function.json

{
    "scriptFile": "__init__.py",
    "bindings": [
        {
            "type": "eventHubTrigger",
            "name": "events",
            "direction": "in",
            "eventHubName": "beta-api-intergration",
            "connection": "receiverConnectionString",
            "cardinality": "many",
            "consumerGroup": "beta-api-consumer",
            "dataType": "binary"
        },
        {
            "name": "betablob",
            "type": "blob",
            "path": "swuploads/{filename}.json",
            "connection": "AzureWebJobsStorage",
            "direction": "in"
        }
    ]
}

init .py

def main(events: List[func.EventHubEvent], betablob: func.InputStream):
    well.login(user,pwd)
    for event in events:
        logging.info('Python EventHub trigger processed an event: %s', event.get_body().decode('utf-8'))

        ###msg contains the file name I want to load in blob
        msg=parse_msg(event) 
        ####how do I pass the file name here ?
        data=load_blob(betablob) 

Under normal circumstances, dynamic binding can be realized indirectly by passing in json format input (or trigger).

For example, send message like this:

{
   "filename":"test"
}

And then binding will get the value 'test'.(This only works for language like python which use declarative bindings.)

But it seems that event hub cannot specify the format of the incoming information, so pure binding cannot be achieved. You need the python-based Azure SDK to implement dynamic binding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM