我在我的C#代码中使用ListBlobsSegmentedAsync来列出所有blob。有没有办法可以将图像和视频与ListBlobsSegmentedAsync的响应分开?
以下是this link的一个例子。您应该能够优化代码来执行yield return
,它将迭代地返回结果,而不是让您的调用代码等待返回所有结果。
public static String WildCardToRegular(String value)
{
return "^" + Regex.Escape(value).Replace("\\*", ".*") + "$";
}
然后,将它与ListBlobsSegmentedAsync一起使用:
var blobList = await container.ListBlobsSegmentedAsync(blobFilePath, true, BlobListingDetails.None, 1000, token, null, null);
var items = blobList.Results.Select(x => x as CloudBlockBlob);
// Filter items by search pattern, if specify
if (!string.IsNullOrEmpty(searchPattern))
{
items = items.Select(i =>
{
var filename = Path.GetFileName(i.Name);
if (Regex.IsMatch(filename, WildCardToRegular(searchPattern), RegexOptions.IgnoreCase))
{
return i;
}
return null;
}).ToList();
}