【发布时间】:2017-06-20 16:55:38
【问题描述】:
我正在尝试根据我的存储帐户中公共 blob 的元数据创建 VideoBlob 对象(标题、描述、路径)的列表。问题是,当我尝试让变量等于 blob 的元数据(“标题”在 blob 的元数据中)时,我得到了
An unhandled exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll
Additional information: The given key was not present in the dictionary.
我也试过添加
blob.FetchAttributes();
但这给了我一个 404 错误。有关如何获取元数据的任何建议?
到目前为止的代码如下所示:
static void iterateThroughContainer(CloudBlobContainer container)
{
List<VideoBlob> blobs = new List<VideoBlob>();
VideoBlob video;
CloudBlockBlob blob;
String tagsString;
foreach (IListBlobItem item in container.ListBlobs(null, true))
{
if (item.GetType() == typeof(CloudBlockBlob))
{
video = new VideoBlob();
blob = container.GetBlockBlobReference(item.Uri.ToString());
video.uri = "test";
Console.WriteLine(blob.Metadata["title"]);
video.title = blob.Metadata["title"];
video.description = blob.Metadata["description"];
video.path = blob.Metadata["path"];
blobs.Add(video);
}
}
}
【问题讨论】:
-
您必须调用 FetchAttributes 才能填充元数据。如果 FetchAttributes 返回 404,则表示您正在尝试访问不存在的 blob。您的问题中没有 FetchAttributes 代码,因此很难看出您可能做错了什么,但这就是您应该开始的地方。 Fiddler 是确保您尝试获取您认为正在访问的 blob 属性的好方法。
-
我刚刚也发现 blob 不存在!您知道获取 blob 名称的任何好方法(在 GetBlockBlobReference 中)吗?
-
没关系,解析 URI。谢谢,kwill!
标签: c# azure azure-storage