C# 如何获取Azure CloudBlobContainer的大小
我正在为我的应用程序创建一个.net包装器服务,它将Azure Blob存储用作文件存储。我的应用程序为我系统上的每个“帐户”创建一个新的C# 如何获取Azure CloudBlobContainer的大小,c#,.net,azure-storage,C#,.net,Azure Storage,我正在为我的应用程序创建一个.net包装器服务,它将Azure Blob存储用作文件存储。我的应用程序为我系统上的每个“帐户”创建一个新的CloudBlobContainer。每个帐户仅限于最大存储量 查询Azure CloudBlobContainer当前大小(空间利用率)的最简单、最有效的方法是什么?FYI以下是答案。希望这有帮助 public static long GetSpaceUsed(string containerName) { var container = Cloud
CloudBlobContainer
。每个帐户仅限于最大存储量
查询Azure CloudBlobContainer当前大小(空间利用率)的最简单、最有效的方法是什么?FYI以下是答案。希望这有帮助
public static long GetSpaceUsed(string containerName)
{
var container = CloudStorageAccount
.Parse(ConfigurationManager.ConnectionStrings["StorageConnection"].ConnectionString)
.CreateCloudBlobClient()
.GetContainerReference(containerName);
if (container.Exists())
{
return (from CloudBlockBlob blob in
container.ListBlobs(useFlatBlobListing: true)
select blob.Properties.Length
).Sum();
}
return 0;
}
从WindwosAzure.Storage.dll(来自Nuget软件包)的v9.x.x.x或更高版本开始,
ListBlobs
方法不再公开。因此,针对.NET Core 2.x+应用程序的解决方案如下所示:
BlobContinuationToken continuationToken = null;
long totalBytes = 0;
do
{
var response = await container.ListBlobsSegmentedAsync(continuationToken);
continuationToken = response.ContinuationToken;
totalBytes += response.Results.OfType<CloudBlockBlob>().Sum(s => s.Properties.Length);
} while (continuationToken != null);
BlobContinuationToken continuationToken=null;
长totalBytes=0;
做
{
var response=wait container.ListBlobsSegmentedAsync(continuationToken);
continuationToken=response.continuationToken;
totalBytes+=response.Results.OfType().Sum(s=>s.Properties.Length);
}while(continuationToken!=null);
现在答案似乎已经很老了。我想问,到目前为止,是否有更好的方法来计算Blob容器的大小?最新版本中不再提供ListBlobs方法。可能存在重复的