【发布时间】:2021-12-31 01:56:52
【问题描述】:
我已查看 Microsoft 提供的有关触发器的文档。 [https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-trigger?tabs=python][1]
确实,在 Azure 函数中使用 func.InputStream 参数允许我们检索 blob 和一些属性 (name, uri, length),我们还可以使用 read() 函数读取字节,但是我们如何将字节转换为我们可以操作的对象,例如 Pandas 数据框(或其他类型文件的任何其他类型的对象,例如 jpg)?
我的 host.json 文件可以在下面找到:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myblob",
"type": "blobTrigger",
"direction": "in",
"path": "statscan/raw/ncdb/{name}",
"connection": ""
},
{
"type": "blob",
"direction": "out",
"name": "outputBlob",
"path": "statscan/enriched/func/{name}.csv",
"connection": ""
}
]
}
Blob Trigger 函数可以在下面找到:
import pandas as pd
import logging
import azure.functions as func
def main(myblob: func.InputStream, outputBlob: func.Out[str]):
logging.info(f"Blob trigger executed!")
logging.info(f"Blob Name: {myblob.name} ({myblob.length}) bytes")
logging.info(f"Full Blob URI: {myblob.uri}")
### Manipulate with Pandas ###
### Output ###
output = ''
outputBlob.set(output)
【问题讨论】: