azure-functions - 读取 Blob 存储 Azure 函数 HttpTrigger
问题描述
尽管在这里或其他地方有很多帖子,但我仍然没有找到如何从 azure 函数读取 blob 存储。
我有如下
上述每个容器都有一个json文件“customer.json”</p>
现在我需要调用我的函数并传递一个参数,例如“london”来检索伦敦客户
Customer customer= await azureFunctionService.GetCustomer(“London”);
函数应该是什么样子,理想情况下我想使用输入绑定从函数中读取 json 文件,但任何其他方式也可以。
[FunctionName("GetCustomer")]
public static void Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
string inputBlobPath,
[Blob("howDoIBuildPathIncludingtheparameter",
FileAccess.Read, Connection = "WhereDoIGetThis")] string json,
ILogger log)
{
// Not sure if anything is required here apart from logging when using input binding
//
}
有什么建议么?
非常感谢
解决方案
此 Microsoft 文档提供了一个简短示例,说明如何从 中提取数据HttpTrigger
以填充 blob 的输入绑定路径:https ://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-expressions-模式#json-payloads
如上所述,单独定义有效负载对象,然后将此类型与HttpTrigger
属性一起使用。然后可以在其他输入绑定表达式中引用对象属性。
public class BlobInfo
{
public string CityName { get; set; }
}
public static class GetCustomer
{
[FunctionName("GetCustomer")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] BlobInfo info,
[Blob("{CityName}/customer.json", FileAccess.Read)] Stream blob,
ILogger log)
{
使用指定所需城市名称的 JSON 有效负载调用此函数,例如curl http://localhost:7071/api/GetCustomer -d "{'CityName':'manchester'}"
.
这将使用名为“manchester”、名为“customer.json”的容器中的 blob 内容初始化 blob 输入参数。
推荐阅读
- http - 主体上带有 Json 的 HTTP POST - Flutter/Dart,响应为空
- macos - 在远程机器 (Ubuntu) 上挂载本地目录 (Mac)
- android - Android TextView 在使用gravity="center" 和ellipsize="end" 设置maxlines="1" 时剪辑文本
- c++ - How to run tests and debug Google Test project in VS Code?
- python - 使用 Python 从 SAP Hana 加载数据时出现语法错误
- python - 使用条件语句对输出值进行分类
- mariadb - 物料清单和 CTE (MariaDB)
- pytorch - pytorch 后向误差,由就地操作修改的梯度计算变量之一
- java - 如何使用 Completable Future 进行外部 API 调用?
- javascript - 如何从 reader.result 获取主要的 base64 值?