【发布时间】:2020-10-15 07:35:54
【问题描述】:
我正在使用带有 javascript 的 Azure 函数,我想在我的函数中修改 path 的输出绑定。例如这是我的function.json:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"name": "outputBlob",
"path": "container/{variableCreatedInFunction}-{rand-guid}",
"connection": "storagename_STORAGE",
"direction": "out",
"type": "blob"
}
]
我想在index.js中设置{variableCreatedInFunction},例如:
module.exports = async function (context, req) {
const data = req.body
const date = new Date().toISOString().slice(0, 10)
const variableCreatedInFunction = `dir/path/${date}`
if (data) {
var responseMessage = `Good`
var statusCode = 200
context.bindings.outputBlob = data
} else {
var responseMessage = `Bad`
var statusCode = 500
}
context.res = {
status: statusCode,
body: responseMessage
};
}
没找到办法,可以吗?
【问题讨论】:
-
javascript 不支持命令式绑定模式,所以我们不能使用 IBinder。我们需要从请求的参数或请求的正文中获取值。还有其他疑问吗?
-
我需要在函数中获取输出 blob 名称。或者至少在函数中获得 rand-guid。那可能吗?我试过这个:
var randGuid = context.bindingData.sys.randGuid但它与绑定中的 guid 不同
标签: javascript node.js azure-functions