gpt4 book ai didi

python - Python 中 Azure Functions 的 Blob 名称模式

转载 作者:行者123 更新时间:2023-12-03 00:59:45 25 4
gpt4 key购买 nike

我正在 Python 中实现一个 Azure 函数,该函数由上传到 blob 存储的文件触发。我想指定文件名的模式并在我的代码中使用其部分,如下所示:

function.json:

{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "inputblob",
"type": "blobTrigger",
"direction": "in",
"path": "dev/sources/{filename}.csv",
"connection": "AzureWebJobsStorage"
}
]
}

执行后的__init__.py文件如下所示:

import logging
import azure.functions as func


def main(inputblob: func.InputStream):
logging.info('Python Blob trigger function processed %s', inputblob.filename)

我收到的错误消息是:AttributeError: 'InputStream' object has no attribute 'filename'。作为引用,我使用了 this documentation .

我是否做错了什么,或者无法在 Python 中实现我想要的目标?

最佳答案

你的函数代码应该是这样的:

import logging
import os

import azure.functions as func


def main(myblob: func.InputStream):
head, filename = os.path.split(myblob.name)
name = os.path.splitext(filename)[0]
logging.info(f"Python blob trigger function processed blob \n"
f"Name without extension: {name}\n"
f"Filename: {filename}")

它应该是名称而不是文件名。:)

关于python - Python 中 Azure Functions 的 Blob 名称模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62549658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com