如何获取Azure CloudBlobContainer的大小 [英] How to get size of Azure CloudBlobContainer
本文介绍了如何获取Azure CloudBlobContainer的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为我的应用程序创建一个.net包装服务,该服务将Azure Blob存储用作文件存储.我的应用程序为系统上的每个帐户"创建了一个新的CloudBlobContainer
.每个帐户限制为最大存储量.
I'm creating a .net wrapper service for my application that utilizes Azure Blob Storage as a file store. My application creates a new CloudBlobContainer
for each "account" on my system. Each account is limited to a maximum amount of storage.
查询Azure CloudBlobContainer当前大小(空间利用率)的最简单,最有效的方法是什么?
What is the simplest and most efficient way to query the current size (space utilization) of an Azure CloudBlobContainer`?
推荐答案
仅供参考,这就是答案.希望这可以帮助.
FYI here's the answer. Hope this helps.
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;
}
这篇关于如何获取Azure CloudBlobContainer的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文