【发布时间】:2022-01-21 17:18:54
【问题描述】:
一年前我有一个有效的 http 触发 Azure 功能。不再。我创建了新的 azure 函数(运行时 ~4),现在我无法在 Azure 编辑器中编译它。它说“[错误] run.csx(2,1):错误 CS0006:找不到元数据文件'Microsoft.WindowsAzure.Storage'”。 它只是从我的 Azure BLOB 存储中获取文件列表。我正在失去理智,我不知道要配置什么,或者如何更改我的代码。不支持 Microsoft.WindowsAzure.Storage 吗? 我想知道降低我的运行时版本,但它是灰色的(我无法更改它)。 我读过这个How to replace Microsoft.WindowsAzure.Storage with Microsoft.Azure.Storage.Blob 但我尝试#r "Azure.Storage.Blobs" 有相同的结果
#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"
using System;
using System.Configuration;
using System.Net;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
string connectionString = "MY_CONNECTION_STRING";
var storageAccount = CloudStorageAccount.Parse(connectionString);
CloudBlobClient client = storageAccount.CreateCloudBlobClient();
string rootDirectoryName = name.Replace(" ", "");
CloudBlobContainer container = client.GetContainerReference("storage");
CloudBlobDirectory folder = container.GetDirectoryReference(rootDirectoryName);
CloudBlobDirectory modelFolder = folder.GetDirectoryReference("giftpics");
BlobResultSegment segment = await modelFolder.ListBlobsSegmentedAsync(null);
List<IListBlobItem> list = new List<IListBlobItem>();
list.AddRange(segment.Results);
while (segment.ContinuationToken != null)
{
segment = await container.ListBlobsSegmentedAsync(segment.ContinuationToken);
list.AddRange(segment.Results);
}
List<string> blobNames = list.OfType<CloudBlockBlob>().Select(b => b.Name.Replace(rootDirectoryName, "").Replace("giftpics", "").Replace("/", "")).ToList();
string contents = JsonConvert.SerializeObject(blobNames);
return new OkObjectResult(contents);
}
【问题讨论】:
标签: c# azure-functions azure-blob-storage