gpt4 book ai didi

Azure ClouddBlob 的 Properties.Length 返回 0

转载 作者:行者123 更新时间:2023-12-04 17:11:36 26 4
gpt4 key购买 nike

以下代码返回大小为 0 的 blob 文件:

public long GetFileSize(string fileUrl)
{
var blob = GetBlobContainer().GetBlobReference(fileUrl);
return blob == null ? 0 : blob.Properties.Length;
}

,它几乎就像没有找到 Blob 一样。但是当我删除该 Blob 时,我发现它被删除了。这在删除时有效:

void DeleteFileFromBlob(string fileUrl, bool deleteSnapshots)
{
var blob = GetBlobContainer().GetBlobReference(fileUrl);
if (deleteSnapshots)
{
var options = new BlobRequestOptions { DeleteSnapshotsOption = DeleteSnapshotsOption.IncludeSnapshots };
blob.DeleteIfExists(options);
}
else blob.DeleteIfExists();
}

与上面的代码基本相同,所以看起来 blob 已找到。

如果我迭代 blob,我会得到正确的 blob 文件大小,就像我计算存储中存储的字节总数时所做的那样:

public long GetStorageUsageByteSize()
{
var blobClient = GetBlobClient();
return (from container in blobClient.ListContainers()
select
(from CloudBlob blob in
container.ListBlobs(new BlobRequestOptions { UseFlatBlobListing = true })
select blob.Properties.Length
).Sum()
).Sum();
}

所以,当我使用带有 url 的 GetBlobReference 时,我无法弄清楚为什么 CloubdBlob::Properties.Length 返回 0。

最佳答案

您似乎缺少对 FetchAttributes 方法的调用,该方法加载 blob 的元数据:

blob.FetchAttributes(); 

引用:https://azure.microsoft.com/en-us/documentation/articles/storage-properties-metadata/

关于Azure ClouddBlob 的 Properties.Length 返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10332295/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com