在Async方法中绑定到输出blob时,将Blob绑定到IAsyncCollector时出错
我试图在这篇文章之后绑定到Async方法中的blob输出: 如何将输出值绑定到我的异步Azure函数?
我有多个输出绑定,所以只返回不是一个选项
public static async Task Run(HttpRequestMessage req, IAsyncCollector collection, TraceWriter log) { if (req.Method == HttpMethod.Post) { string jsonContent = await req.Content.ReadAsStringAsync(); // Save to blob await collection.AddAsync(jsonContent); return req.CreateResponse(HttpStatusCode.OK); } else { return req.CreateResponse(HttpStatusCode.BadRequest); } }
我对blob的绑定是:
{ "bindings": [ { "authLevel": "function", "name": "req", "type": "httpTrigger", "direction": "in" }, { "name": "$return", "type": "http", "direction": "out" }, { "type": "blob", "name": "collection", "path": "testdata/{rand-guid}.txt", "connection": "test_STORAGE", "direction": "out" } ], "disabled": false }
但每当我这样做,我得到以下内容:
错误:函数($ WebHook)错误:Microsoft.Azure.WebJobs.Host:错误索引方法’Functions.WebHook’。 Microsoft.Azure.WebJobs.Host:无法绑定Blob以键入’Microsoft.Azure.WebJobs.IAsyncCollector`1 [System.String]’
Blob输出绑定不支持收集器,请参阅此问题 。
对于可变数量的输出blob(在您的情况下为0或1,但可以是任何),您将不得不使用命令式绑定。 从function.json
删除collection
绑定,然后执行以下操作:
public static async Task Run(HttpRequestMessage req, Binder binder) { if (req.Method == HttpMethod.Post) { string jsonContent = await req.Content.ReadAsStringAsync(); var attributes = new Attribute[] { new BlobAttribute("testdata/{rand-guid}.txt"), new StorageAccountAttribute("test_STORAGE") }; using (var writer = await binder.BindAsync(attributes)) { writer.Write(jsonContent); } return req.CreateResponse(HttpStatusCode.OK); } else { return req.CreateResponse(HttpStatusCode.BadRequest); } }
- 图Api – 401未经授权
- 如何复制Azure容器和Blob
- 无法加载文件或程序集FSharp.Core,Version = 4.0.0.0 Azure Web Role
- 使用Windows Azure DiagnosticsMonitor时,log4net traceappender仅记录级别为“详细”的消息
- 将类设置为Serializable的缺点
- 在Windows 8和Windows Phone 8中使用数据库的正确方法
- 从用于Google API的Azure网站中的p12证书生成X509Certificate2时出现502错误
- Azure移动应用程序 – 尝试POST时获取405(方法不允许)
- QueueClient.Receive()的异步方法?