微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Azure.Storage.Blob 文件夹结构

如何解决Azure.Storage.Blob 文件夹结构

几年来,我们已经使用已折旧的 WindowsAzure.Storage nuget 在 Azure 上进行了现有实施。

我们正在将 nuget 升级到新的 Azure.Storage.Blobs nuget。

作为原始实现的一部分,blob 将存储在容器内的文件夹结构中:container/year/month/:

  • test/2021/01/test.pdf
  • test/2020/12/test.pdf

要求是应该继续下去,但如果可能的话,我不能再锻炼了。

有没有人设法让它工作?

解决方法

您可以通过代码简单地创建它:

using Azure.Storage;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;

// Get a connection string to our Azure Storage account.  You can
// obtain your connection string from the Azure Portal (click
// Access Keys under Settings in the Portal Storage account blade)
// or using the Azure CLI with:
//
//     az storage account show-connection-string --name <account_name> --resource-group <resource_group>
//
// And you can provide the connection string to your application
// using an environment variable.
string connectionString = "<connection_string>";

// Get a reference to a container named "sample-container" and then create it
BlobContainerClient container = new BlobContainerClient(connectionString,"sample-container");
container.Create();

// Get a reference to a blob named "sample-file" in a container named "sample-container"
BlobClient blob = container.GetBlobClient("sample-folder/sample-file");

// Open a file and upload it's data
using (FileStream file = File.OpenRead("local-file.jpg"))
{
    blob.Upload(file);
}

查看有关此 nuget 的 documentation from PG

,

在 Azure 的 Blob 存储中,您没有所谓的文件夹结构。这都是虚拟的。如果您在代码的 blob 引用部分中使用您希望的完整路径(在您的情况下为年/月)指定 blob 的名称,则可以保留与上传 blob 相同的逻辑。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。