我正在尝试通过Azure函数访问Blob存储中的内容。我有以下内容:
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
public static async Task<HttpResponseMessage> Run(HttpRequest req, ILogger log)
{
string path = req.Query["path"];
string storageConnectionString = "...";
CloudStorageAccount blobAccount = CloudStorageAccount.Parse(storageConnectionString);
CloudBlobClient blobClient = blobAccount.CreateCloudBlobClient();
CloudBlobContainer blobContainer = blobClient.GetContainerReference("content");
CloudBlockBlob cloudBlockBlob = blobContainer.GetBlockBlobReference(path);*
return new HttpResponseMessage(HttpStatusCode.OK) {
Content = /* to do - content of blob */
};
}
但是,我正在努力告诉该函数识别Microsoft.WindowsAzure.Storage命名空间:
2019-11-07T09:59:57.729 [Error] run.csx(7,17): error CS0234: The type or namespace name 'WindowsAzure' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
我觉得我对Azure函数的理解缺少一些主要知识,因为从Azure函数中引入名称空间/包以与Azure一起使用并不是挑战。
非常感谢!
答案 0 :(得分:0)
在c#脚本功能中,您无需初始化blob客户端即可读取blob。 Azure函数提供Blob绑定以读取/写入Blob,请检查此文档:default value。
首先转到功能集成,如下图所示进行设置。这样,只需绑定max_depth=1
即可流式传输以读取内容或绑定到inputBlob
类型,而只需使用CloudBlockBlob
方法。
并且该路径支持绑定到容器,并且在函数中仅绑定到CloudBlockBlob
类型。
以下是我读取文本文件的测试代码。
CloudBlobContainer
希望这可以为您提供帮助,如果仍然有其他问题,请随时告诉我。