【发布时间】:2021-06-01 22:07:45
【问题描述】:
我使用 Azure 函数作为 Webhook Consumer 以 JSON 形式接收 http 事件并将其存储在 Azure 存储中。 我想根据日期对输出 blob 路径进行动态命名,如下所示。我尝试了很多选项,但无法获得所需的输出。 我关注了这个post 但没有运气。
例外的写入路径:
source/
ctry/
yyyy/
mm/
date/
hrs/
event_{systemtime}.json
function.json:
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
},
{
"type": "blob",
"name": "outputblob",
"path": "source/ctry/{datetime:yyyy}/{datetime:MM}/{datetime:dd}/{datetime:hh}/event_{systemtime}.json",
"direction": "out",
"connection": "MyStorageConnectionAppSetting"
}
]
}
init.py
import logging
import azure.functions as func
def main(req: func.HttpRequest,outputblob: func.Out[str]) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = 'some_name'
if not name:
try:
req_body = 'req_body_test'#req.get_json()
except ValueError:
pass
else:
name = 'name'#req_body.get('name')
print(str(req.get_json()))
outputblob.set(str(req.get_json()))
【问题讨论】:
-
什么是绑定表达式 {systemtime} 假设我以前没见过
标签: python azure datetime azure-functions azure-storage