下面的代碼能夠將指定目錄中的文件上傳localPath到 Azure Blob 存儲容器。問題是文件沒有放置在容器的根目錄中,而是創建了與變量定義的文件路徑匹配的文件夾localPath。string localPath = @"C:\example\path\to\files";生成的 blob 容器如下所示。.+-- example| +-- path| +-- to| +-- files| +-- file1.json| +-- file2.json| +-- file3.json| +-- file4.json| +-- file5.json需要對下面的代碼進行哪些更改,以便將文件移動到容器的根目錄,而不是移動到與 匹配的文件夾結構中localPath?程序.csnamespace AzureBlobStorageFileTransfer{ using Microsoft.Azure.Storage; using Microsoft.Azure.Storage.Blob; using System; using System.IO; using System.Threading.Tasks; public static class Program { public static void Main() { ProcessAsync().GetAwaiter().GetResult(); } private static async Task ProcessAsync() { CloudStorageAccount storageAccount = null; CloudBlobContainer cloudBlobContainer = null; string storageConnectionString = Environment.GetEnvironmentVariable("storageconnectionstring"); if (CloudStorageAccount.TryParse(storageConnectionString, out storageAccount)) { try { CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient(); cloudBlobContainer = cloudBlobClient.GetContainerReference("example"); BlobContainerPermissions permissions = new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }; await cloudBlobContainer.SetPermissionsAsync(permissions); string localPath = @"C:\example\path\to\files"; var txtFiles = Directory.EnumerateFiles(localPath, "*.json");
如何在沒有文件路徑的情況下將文件上傳到 Azure Blob 存儲容器的根目錄
慕尼黑8549860
2024-01-20 21:02:22