gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 19:54:03 24 4
gpt4 key购买 nike

我在 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/

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