c# - 从 C# 读取 Azure Blob 存储中的文件

标签 c# azure blob azure-blob-storage

我在 Azure 存储中有一个 Blob 容器,然后是一个文件夹,然后是一个子文件夹,然后是不同的文件 (ContainerName/Folder1/Subfolder1/files...)。 如何读取该 Subfolder1 目录中的所有文件?假设我有一些 pdf 文件,我需要将它们放入我的应用程序中,我该怎么做?

最佳答案

嗯,它并不是真正的子文件夹,它只是一个路径。

作为documentation for ListBlobs说:

You can optionally specify a blob prefix to list blobs whose names begin with the same string. If you use a delimiter character in your blob names to create a virtual directory structure, the blob prefix can include all or part of the virtual directory structure (but not the container name).

因此,您可以使用 Folder1/Subfolder1 中的 pass 作为前缀:

var container = blobClient.GetContainerReference(containerName);
foreach (var file in container.ListBlobs(prefix: "Folder1/Subfolder1", useFlatBlobListing: true))
{ 
    // etc

注意:我不记得前缀是否需要前导斜杠或尾随斜杠或两者都需要。

prefix 参数确保只有以参数值开头的 blob 名称才会作为列表的一部分返回。 useFlatBlobListing 参数将确保如果前缀中指定的子文件夹内的嵌套文件夹中存在任何 Blob,也会返回。

关于c# - 从 C# 读取 Azure Blob 存储中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44202701/

相关文章:

c# - sharpsvn 日志消息编辑 sharpsvn?

azure - Windows Azure 计算模拟器错误

azure - 使用 Azcopy 复制表存储

Azure Python 函数服务总线出站属性

c# - LINQ 查询中的对象初始值设定项 - 是否可以重用计算数据?

c# - 如何获取 Android 应用程序当前使用的堆大小?

javascript - 在 DOM 中插入文件输入作为 img

azure - 如何将文件保存到 Azure blob 容器中的子文件夹?

php - 如何使用Mysql blob下载没有html的文件

c# - Boost::Asio 写锁