为什么 Azure API 不列出名为 /folder/folder/file 的 blob?
Why doesn't Azure API list the blobs that is named /folder/folder/file?
我想创建文件夹和子文件夹,我找到了 this workaround:
但是当我列出它们时:使用此代码 (source):
foreach (IListBlobItem item in Container.ListBlobs(null, false))
{
if (item.GetType() == typeof(CloudBlockBlob))
{
CloudBlockBlob blob = (CloudBlockBlob)item;
Console.WriteLine("Block blob of length {0}: {1}", blob.Properties.Length, blob.Uri);
}
else if (item.GetType() == typeof(CloudPageBlob))
{
CloudPageBlob pageBlob = (CloudPageBlob)item;
Console.WriteLine("Page blob of length {0}: {1}", pageBlob.Properties.Length, pageBlob.Uri);
}
else if (item.GetType() == typeof(CloudBlobDirectory))
{
CloudBlobDirectory directory = (CloudBlobDirectory)item;
Console.WriteLine("Directory: {0}", directory.Uri);
}
}
它只显示根容器中的父文件夹和 blob。
我期望将它们全部作为 blob,因为这是虚拟目录而不是真实的,
例如我有这个文件
https://account.blob.core.windows.net/container/Accounts/Images/1/acc.jpg
但是不显示,只显示:
https://account.blob.core.windows.net/container/Accounts
和
https://account.blob.core.windows.net/container/anyfile
我是否必须请求父文件夹中的子文件夹才能访问文件?
请尝试在 ListBlobs
方法中将第二个参数指定为 true
。此参数指示您是想要平面 blob 列表 (true) 还是分层 blob 列表 (false)。
来自文档link:
useFlatBlobListing
Type: System.Boolean
A boolean value that specifies whether to list blobs in a flat
listing, or whether to list blobs hierarchically, by virtual
directory.
如果有人正在寻找带有最新 Azure.Storage.Blobs SDK 的此类平面文件列表,您可以这样做:
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient(resource.Name);
var blobItemList = blobContainerClient.GetBlobs(); // This will get blobs without any hierarchy
我想创建文件夹和子文件夹,我找到了 this workaround: 但是当我列出它们时:使用此代码 (source):
foreach (IListBlobItem item in Container.ListBlobs(null, false))
{
if (item.GetType() == typeof(CloudBlockBlob))
{
CloudBlockBlob blob = (CloudBlockBlob)item;
Console.WriteLine("Block blob of length {0}: {1}", blob.Properties.Length, blob.Uri);
}
else if (item.GetType() == typeof(CloudPageBlob))
{
CloudPageBlob pageBlob = (CloudPageBlob)item;
Console.WriteLine("Page blob of length {0}: {1}", pageBlob.Properties.Length, pageBlob.Uri);
}
else if (item.GetType() == typeof(CloudBlobDirectory))
{
CloudBlobDirectory directory = (CloudBlobDirectory)item;
Console.WriteLine("Directory: {0}", directory.Uri);
}
}
它只显示根容器中的父文件夹和 blob。 我期望将它们全部作为 blob,因为这是虚拟目录而不是真实的, 例如我有这个文件
https://account.blob.core.windows.net/container/Accounts/Images/1/acc.jpg
但是不显示,只显示:
https://account.blob.core.windows.net/container/Accounts
和
https://account.blob.core.windows.net/container/anyfile
我是否必须请求父文件夹中的子文件夹才能访问文件?
请尝试在 ListBlobs
方法中将第二个参数指定为 true
。此参数指示您是想要平面 blob 列表 (true) 还是分层 blob 列表 (false)。
来自文档link:
useFlatBlobListing
Type: System.Boolean
A boolean value that specifies whether to list blobs in a flat listing, or whether to list blobs hierarchically, by virtual directory.
如果有人正在寻找带有最新 Azure.Storage.Blobs SDK 的此类平面文件列表,您可以这样做:
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient(resource.Name);
var blobItemList = blobContainerClient.GetBlobs(); // This will get blobs without any hierarchy