将存档上传到容器 blob Azure 中的特定文件夹
Posted
技术标签:
【中文标题】将存档上传到容器 blob Azure 中的特定文件夹【英文标题】:Upload archive to specific folder in Container blobs Azure 【发布时间】:2022-01-12 16:11:58 【问题描述】:如何将文件上传到 Azure 容器内的特定文件夹?
我正在使用下面的代码,它工作正常,但它保存在容器根目录中。
var connectionString = "xxxxxx";
string containerName = "projects";
var serviceClient = new BlobServiceClient(connectionString);
var containerClient = serviceClient.GetBlobContainerClient(containerName);
var path2 = @"C:\2021\BlobContainer\";
var fileName2 = dados.after.NR_RA + "_" + DateTime.Now.ToString("ddmmyyyyHHmm") + ".txt";
var localFile = Path.Combine(path2, fileName2);
var blobClient = containerClient.GetBlobClient(fileName2);
Console.WriteLine("Uploading to Blob storage");
using FileStream uploadFileStream = File.OpenRead(localFile);
await blobClient.UploadAsync(uploadFileStream, true);
uploadFileStream.Close();
【问题讨论】:
【参考方案1】:整理好了!
如本文所述:
How to save a file to a subfolder in an Azure blob container?
需要改变:
var blobClient = containerClient.GetBlobClient(fileName2);
对于
var blobClient = containerClient.GetBlobClient("Folder1/" + fileName2);
获取如下代码:
var connectionString = "xxxxxx";
string containerName = "projects";
var serviceClient = new BlobServiceClient(connectionString);
var containerClient = serviceClient.GetBlobContainerClient(containerName);
var path2 = @"C:\2021\BlobContainer\";
var fileName2 = dados.after.NR_RA + "_" + DateTime.Now.ToString("ddmmyyyyHHmm") + ".txt";
var localFile = Path.Combine(path2, fileName2);
var blobClient = containerClient.GetBlobClient("Folder1/" + fileName2);
Console.WriteLine("Uploading to Blob storage");
using FileStream uploadFileStream = File.OpenRead(localFile);
await blobClient.UploadAsync(uploadFileStream, true);
uploadFileStream.Close();
得到提示!!!
【讨论】:
以上是关于将存档上传到容器 blob Azure 中的特定文件夹的主要内容,如果未能解决你的问题,请参考以下文章
如何将静态文件添加/上传到 Azure Blob 存储容器的特定路径
我需要将 SQL Azure 中的媒体内容(视频或图像)存储上传到 Azure BLOB 容器