需要帮助,
尝试获取存储在blob-container中的项目列表,但无法理解为什么会超时。
我得到的错误是: -
ReadTimeout'((System.IO.Stream)(swa.BaseStream))。ReadTimeout'抛出类型'System.InvalidOperationException'的异常int {System.InvalidOperationException}
详细错误消息:
使用以下代码:https://docs.microsoft.com/en-us/azure/storage/blobs/storage-dotnet-how-to-use-blobs
所以在下面的代码中 - resultSegment获得Result count = 2327但是在listblob.txt上只导出--2279然后它超时
namespace listblob
{
class Program
{
static void Main(string[] args)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("containername");
ListBlobsSegmentedInFlatListing(container).Wait();
}
async public static Task ListBlobsSegmentedInFlatListing(CloudBlobContainer container)
{
int i = 0;
BlobContinuationToken continuationToken = null;
BlobResultSegment resultSegment = null;
string patha = @"C:\listblob.txt";
StreamWriter swa = File.CreateText(patha);
do
{
resultSegment = await container.ListBlobsSegmentedAsync("", true, BlobListingDetails.All, 10, continuationToken, null, null);
if (resultSegment.Results.Count<IListBlobItem>() > 0) //{ Console.WriteLine("Page {0}:", ++i); }
foreach (var blobItem in resultSegment.Results)
{
//Console.WriteLine("\t{0}", blobItem.StorageUri.PrimaryUri);
swa.WriteLine(blobItem.Uri.Segments[2]);
}
.
continuationToken = resultSegment.ContinuationToken;
}
while (continuationToken != null);
}
}
}
答案 0 :(得分:1)
感谢Thennarasan的回复。我根据你的建议尝试过,但结果没有变化。
然而,我将所有复制到字符串列表并获得预期结果。
List<String> list = new List<String>();
list.Add(blobItem.Uri.Segments[2]);
System.IO.File.WriteAllLines("SavedLists.txt", list);
答案 1 :(得分:0)
List<string> blobNames = list.OfType<CloudBlockBlob>().Select(b => b.Name).ToList();
尝试使用这种方式