gpt4 book ai didi

c# - 如何将文件夹上传到 Azure 存储

转载 作者:太空宇宙 更新时间:2023-11-03 17:30:07 26 4
gpt4 key购买 nike

我想将整个文件夹上传到 azure 存储。我知道我可以使用以下方式上传文件:

blobReference.UploadFromFile(fileName);

但找不到上传整个文件夹的方法(递归)。有这样的方法吗?或者也许是示例代码?

谢谢

最佳答案

文件夹结构可以只是文件名的一部分:

string myfolder = "datadir";
string myfilename = "mydatafile";
string fileName = String.Format("{0}/{1}.csv", myfolder, myfilename);
CloudBlockBlob blob = container.GetBlockBlobReference(fileName);

如果您像此示例一样上传,文件将出现在容器的“datadir”文件夹中。

这意味着您可以使用它来复制要上传的目录结构:

foreach (string file in Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories)) {
    // file would look like "C:\dir1\dir2\blah.txt"

// Don't know if this is the prettiest way, but it will work:
string cloudfilename = file.Substring(3).Replace('\\', '/');

// get the blob reference and push the file contents to it:
CloudBlockBlob blob = container.GetBlockBlobReference(cloudfileName);
blob.UploadFromFile(file);
  }

关于c# - 如何将文件夹上传到 Azure 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43606539/

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