对 Azure Functions 非常非常陌生,并且感到非常沮丧。
我想要做的就是执行来自 HttpTriggerFunction 的“get”请求并从 CloudBlobContainer 返回流内容。
我真的不明白为什么这么难。只是尝试使用 Azure Functions 托管 SPA。
类似这样的
public static class UIHandler
{
[FunctionName("UIHandler")]
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequest req,
TraceWriter log,
CloudBlobContainer container)
{
log.Info("C# HTTP trigger function processed a request.");
var stream = await container.GetBlockBlobReference({Infer file name from request here}).OpenReadAsync();
return new HttpResponseMessage()
{
StatusCode = HttpStatusCode.OK,
Content = new StreamContent(stream)
};
}
}
当我尝试运行此程序时,出现以下错误。
Run: Microsoft.Azure.WebJobs.Host: Error indexing method 'UIHandler.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'container' to type CloudBlobContainer. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
我正在使用 Azure Functions 2。我无法从网上看到如何为此设置浏览扩展。我还研究了输入和输出绑定(bind)。我不明白当您使用似乎只存在于 JSON 中的 C# 时,是什么使参数输入或输出绑定(bind)。
我需要相应的 JSON 文件吗?如果是的话,它叫什么,它去哪里了。
提前致谢
最佳答案
看看Blob Storage Input Binding 。第一个示例展示了如何读取 blob 流,只需将队列触发器替换为 HTTP 触发器,例如
[FunctionName("UIHandler")]
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "{name}")] HttpRequest req,
string name,
TraceWriter log,
[Blob("samples-workitems/{name}", FileAccess.Read)] Stream stream)
{
log.Info($"C# HTTP trigger function processed a request for {name}.");
return new HttpResponseMessage()
{
StatusCode = HttpStatusCode.OK,
Content = new StreamContent(stream)
};
}
关于c# - Azure函数从HttpTriggerFunction访问CloudBlobContainer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51211876/