繁体   English   中英

如何从Azure Function Python动态读取blob文件

[英]How to dynamically read blob file from Azure Function Python

我希望能够使用 Azure Function Python 动态读取 blob 文件 (json),文件名通过 Azure 事件中心消息传递。 我如何使用 Azure 绑定来做到这一点?

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

初始化.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) 

一般情况下,可以通过传入json格式的输入(或触发)间接实现动态绑定。

例如,发送这样的消息:

{
   "filename":"test"
}

然后绑定将获得值“test”。(这仅适用于使用声明性绑定的语言,如 python。)

但是event hub好像不能指定传入信息的格式,所以无法实现纯绑定。 需要基于python的 Azure SDK 来实现动态绑定。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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