如何从 Azure 计时器触发器函数引用 blob?
How do you reference a blob from an Azure Timer Trigger Function?
我有一个 Azure 计时器触发器函数,它应该进行一些计算并将结果写入预先存在的 blob 中的 json 文件。如何从 Timer Triggered 函数中引用预先存在的 blob?
我似乎找不到任何提供代码示例的文档。有人可以提供吗?
首先,您需要更新 function.json 配置文件,以将 blob 绑定到您将在 .csx 代码中使用的 CloudBlockBlob 实例。您可以在 Azure 门户中通过函数应用程序菜单中函数下的 "Integrate" 选项(带有照明图标的选项)对其进行编辑。该页面的右上角是 link,上面写着 "Advanced Editor"。单击 link 将带您到函数的 function.json 文件:
您会看到一个名为 "bindings" 的 JSON 数组,其中包含一个配置计时器的 JSON 对象。您需要向该数组添加另一个 JSON 对象,以将您的 blob 绑定到您将在函数中引用的 CloudBlockBlob 实例。您的 function.json 文件将如下所示:
{
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */5 * * * *"
},
{
"type": "blob",
"name": "myBlob",
"path": "your-container-name/your_blob_filename.json",
"connection": "AzureWebJobsStorage",
"direction": "inout"
}
],
"disabled": false
}
现在您只需更新函数的 运行 方法的签名。默认情况下看起来像这样:
public static void Run(TimerInfo myTimer, TraceWriter log)
将您的 blob 变量添加到该签名的末尾(并添加必要的包含):
#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
public static void Run(TimerInfo myTimer, TraceWriter log, CloudBlockBlob myBlob)
大功告成! "myBlob" 绑定到 "your-container-name" 容器中的 blob "your_blob_filename.json"。
我有一个 Azure 计时器触发器函数,它应该进行一些计算并将结果写入预先存在的 blob 中的 json 文件。如何从 Timer Triggered 函数中引用预先存在的 blob?
我似乎找不到任何提供代码示例的文档。有人可以提供吗?
首先,您需要更新 function.json 配置文件,以将 blob 绑定到您将在 .csx 代码中使用的 CloudBlockBlob 实例。您可以在 Azure 门户中通过函数应用程序菜单中函数下的 "Integrate" 选项(带有照明图标的选项)对其进行编辑。该页面的右上角是 link,上面写着 "Advanced Editor"。单击 link 将带您到函数的 function.json 文件:
您会看到一个名为 "bindings" 的 JSON 数组,其中包含一个配置计时器的 JSON 对象。您需要向该数组添加另一个 JSON 对象,以将您的 blob 绑定到您将在函数中引用的 CloudBlockBlob 实例。您的 function.json 文件将如下所示:
{
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */5 * * * *"
},
{
"type": "blob",
"name": "myBlob",
"path": "your-container-name/your_blob_filename.json",
"connection": "AzureWebJobsStorage",
"direction": "inout"
}
],
"disabled": false
}
现在您只需更新函数的 运行 方法的签名。默认情况下看起来像这样:
public static void Run(TimerInfo myTimer, TraceWriter log)
将您的 blob 变量添加到该签名的末尾(并添加必要的包含):
#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
public static void Run(TimerInfo myTimer, TraceWriter log, CloudBlockBlob myBlob)
大功告成! "myBlob" 绑定到 "your-container-name" 容器中的 blob "your_blob_filename.json"。