[英]Process csv file stored in blob storage using Python Azure functions
I have a csv file with 'n' number of records stored in blob storage.我有一个 csv 文件,其中存储在 blob 存储中的记录数为“n”。 I want to read the new records being added to the csv file, process it and stored it back to another container in the blob storage.
我想读取添加到 csv 文件中的新记录,对其进行处理并将其存储回 blob 存储中的另一个容器。 I want to achieve this flow using Python Azure Functions.
我想使用 Python Azure Functions 来实现这个流程。 I am unable to write the code for inbound and outbound in the Python Azure Functions.
我无法在 Python Azure Functions 中编写入站和出站代码。
Please help.请帮忙。 Thanks
谢谢
Below is the code that worked for me.下面是对我有用的代码。 I'm using HTTP Trigger to achieve your requirement.
我正在使用 HTTP 触发器来满足您的要求。
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "blob",
"direction":"in",
"name": "inputblob",
"path": "input/input.csv",
"connection": "storageacc_STORAGE"
},
{
"type": "blob",
"direction":"out",
"name": "outputblob",
"path": "output/output.csv",
"connection": "storageacc_STORAGE"
}
]
}
import csv
import logging
import azure.functions as func
def main(req: func.HttpRequest, inputblob: func.InputStream,outputblob: func.Out[bytes]) -> func.InputStream:
# Reading from the input binding
input_file = inputblob.read()
# Processing the csv file
# Writing to output binding
outputblob.set(input_file)
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "python",
"storageacc_STORAGE": "<Your_Connection_String>"
}
}
RESULTS:结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.