Azure 函数绑定不起作用
Azure Functions Bindings not working
我收到这个错误:
Microsoft.Azure.WebJobs.Host: Only the 'Read' FileAccess mode is
supported for blob container bindings.
而根据docs,out应该是支持的吧?
我最初尝试在方法定义中添加 Attributes
。但是,我得到了同样的错误,所以我删除了我的方法定义中的所有属性,所以新的方法定义是:
public static async Task RunAsync(CloudBlockBlob myBlob, string name,
IAsyncCollector<ProfilePictureUrl> client, CloudBlockBlob resizedBlob, TraceWriter log)
这是我的 function.json
{
"bindings": [
{
"type": "blobTrigger",
"path": "profile-pictures/{name}",
"direction": "in",
"name": "myBlob"
},
{
"type": "documentDB",
"databaseName": "TestDB",
"collectionName": "ResizedProfilePictures",
"createIfNotExists": true,
"direction": "out",
"name": "client"
},
{
"type": "blob",
"path": "resized-profile-pictures",
"direction": "out",
"name": "resizedBlob"
}
],
"disabled": false,
"scriptFile": "..\Test.Functions.dll",
"entryPoint": "Test.Functions.ResizeImage.RunAsync"
}
我正在使用 Azure CLI beta 100。如果我从方法定义中删除 resizedBlob
和 function.json,那么它工作正常。
CloudBlobContainer
不是 listed 作为输出绑定支持的类型。因此,您需要使用列出的类型之一。
我猜,您正在尝试动态设置输出文件的名称。为此,您需要将名称绑定到触发器参数(例如 {name}
),或者使用命令式绑定(就像您已经对输出绑定所做的那样)。
如果您有其他用例,请使用代码示例扩展您的问题。
如果您确实需要 CloudBlobContainer
参数,请将其列为另一个 in
绑定。
CloudBlobContainer 必须作为 input 绑定进行绑定。这是一个工作示例:
#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage.Blob;
public static void Run(Stream input, Stream output,
CloudBlobContainer container, TraceWriter log)
{
var blobs = container.ListBlobs();
log.Info($"{blobs.Count()} blobs in container.");
}
和对应的function.json:
{
"bindings": [
{
"name": "input",
"type": "blobTrigger",
"direction": "in",
"path": "input/{name}",
"connection": "test_STORAGE"
},
{
"name": "container",
"type": "blob",
"direction": "in",
"path": "input",
"connection": "test_STORAGE"
}
]
}
这应该适用于新发布的 Functions VS 工具(非预览版)。你能更新到最新的位吗?
对于 VS 工具,Functions 现在以与 webjobs 相同的方式直接加载 DLL,因此所有 webjobs 绑定都将按原样工作。 Function.json 中唯一的东西就是触发器绑定和 "configurationSource":"attributes" 属性。 属性 告诉它使用属性而不是 function.json。 [1]
[1] 参见 https://github.com/Azure/azure-webjobs-sdk-script/issues/1508
该问题是一个错误,现已在最新版本的功能中修复。
https://github.com/Azure/azure-webjobs-sdk-script/issues/1783
我收到这个错误:
Microsoft.Azure.WebJobs.Host: Only the 'Read' FileAccess mode is supported for blob container bindings.
而根据docs,out应该是支持的吧?
我最初尝试在方法定义中添加 Attributes
。但是,我得到了同样的错误,所以我删除了我的方法定义中的所有属性,所以新的方法定义是:
public static async Task RunAsync(CloudBlockBlob myBlob, string name,
IAsyncCollector<ProfilePictureUrl> client, CloudBlockBlob resizedBlob, TraceWriter log)
这是我的 function.json
{
"bindings": [
{
"type": "blobTrigger",
"path": "profile-pictures/{name}",
"direction": "in",
"name": "myBlob"
},
{
"type": "documentDB",
"databaseName": "TestDB",
"collectionName": "ResizedProfilePictures",
"createIfNotExists": true,
"direction": "out",
"name": "client"
},
{
"type": "blob",
"path": "resized-profile-pictures",
"direction": "out",
"name": "resizedBlob"
}
],
"disabled": false,
"scriptFile": "..\Test.Functions.dll",
"entryPoint": "Test.Functions.ResizeImage.RunAsync"
}
我正在使用 Azure CLI beta 100。如果我从方法定义中删除 resizedBlob
和 function.json,那么它工作正常。
CloudBlobContainer
不是 listed 作为输出绑定支持的类型。因此,您需要使用列出的类型之一。
我猜,您正在尝试动态设置输出文件的名称。为此,您需要将名称绑定到触发器参数(例如 {name}
),或者使用命令式绑定(就像您已经对输出绑定所做的那样)。
如果您有其他用例,请使用代码示例扩展您的问题。
如果您确实需要 CloudBlobContainer
参数,请将其列为另一个 in
绑定。
CloudBlobContainer 必须作为 input 绑定进行绑定。这是一个工作示例:
#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage.Blob;
public static void Run(Stream input, Stream output,
CloudBlobContainer container, TraceWriter log)
{
var blobs = container.ListBlobs();
log.Info($"{blobs.Count()} blobs in container.");
}
和对应的function.json:
{
"bindings": [
{
"name": "input",
"type": "blobTrigger",
"direction": "in",
"path": "input/{name}",
"connection": "test_STORAGE"
},
{
"name": "container",
"type": "blob",
"direction": "in",
"path": "input",
"connection": "test_STORAGE"
}
]
}
这应该适用于新发布的 Functions VS 工具(非预览版)。你能更新到最新的位吗?
对于 VS 工具,Functions 现在以与 webjobs 相同的方式直接加载 DLL,因此所有 webjobs 绑定都将按原样工作。 Function.json 中唯一的东西就是触发器绑定和 "configurationSource":"attributes" 属性。 属性 告诉它使用属性而不是 function.json。 [1]
[1] 参见 https://github.com/Azure/azure-webjobs-sdk-script/issues/1508
该问题是一个错误,现已在最新版本的功能中修复。
https://github.com/Azure/azure-webjobs-sdk-script/issues/1783