简体   繁体   English

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

[英]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.我希望能够使用 Azure Function Python 动态读取 blob 文件 (json),文件名通过 Azure 事件中心消息传递。 How can I do that with Azure Bindings?我如何使用 Azure 绑定来做到这一点?

function.json 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初始化.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).一般情况下,可以通过传入json格式的输入(或触发)间接实现动态绑定。

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.)然后绑定将获得值“test”。(这仅适用于使用声明性绑定的语言,如 python。)

But it seems that event hub cannot specify the format of the incoming information, so pure binding cannot be achieved.但是event hub好像不能指定传入信息的格式,所以无法实现纯绑定。 You need the python-based Azure SDK to implement dynamic binding.需要基于python的 Azure SDK 来实现动态绑定。

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

相关问题 如何在 python 中使用 Azure 函数读取 Azure blob 文件? - how to read the Azure blob file with Azure function in python? 如何从 Azure function 在 Z23EEEB4347BDD26BDDFC6B75 - How to read xlsx blob into pandas from Azure function in python 如何从 Azure Python function blob 输入绑定中读取镶木地板文件? - How to read parquet file from Azure Python function blob input binding? 如何使用 Python 从 Azure Blob 容器读取文件 - How to read a file from Azure Blob Container using Python 从 python 中的 azure blob 存储读取文件 - read file from azure blob storage in python 如何使用 Azure 函数从 Blob 存储中读取 json 文件 Python - How to read json file from blob storage using Azure Functions Blob Trigger with Python 如何使用 python 和 pandas read_fwf ZC1C42542074E68384F5D1 处理位于 Azure blob 存储中的文件 - How to process a file located in Azure blob Storage using python with pandas read_fwf function AZURE Function 从 AZURE BLOB 读取 XLSX - AZURE Function read XLSX from AZURE BLOB 如何使用 Python delta-rs 从 Azure Blob 存储中读取数据 - How to read from Azure Blob Storage with Python delta-rs 如何从 Azure blob 存储中将镶木地板文件读入 pandas - How to read parquet file into pandas from Azure blob store
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM