【发布时间】:2021-01-12 15:07:14
【问题描述】:
我是 Azure Functions 的新手,在一些基础知识方面遇到了问题,特别是如何将参数数据传递给 function.json,以便我可以使用存储连接器将 blob 写入 Azure Blob 存储。
我的问题是,如何在 httpTrigger 函数中指定一个可供下面的 outputBlobContents 绑定使用的参数?
我的设置很简单(但还不行):
function.json:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "blob",
"direction": "out",
"name": "outputBlobContents",
"path": "uploaded_files/{destinationFilename}",
"connection": "MY_STORAGE"
}
]
}
index.ts:
import { AzureFunction, Context, HttpRequest } from "@azure/functions"
const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
context.bindingData.destinationFilename = "testfile.pdf";
context.bindings.outputBlobContents = context.req.body;
const responseMessage = "uploaded file";
context.res = {
status: 201,
body: responseMessage
};
};
export default httpTrigger;
在我的示例代码中,我尝试将destinationFilename 分配给context.bindingData 对象,但这不起作用。我已经阅读了所有文档,但对于 bindingData 对象实际上是什么或命名参数通常如何工作并不是很清楚。如何告诉 blob 存储连接器将文件存储在哪里?
【问题讨论】:
标签: javascript azure azure-functions