下面的代碼能夠?qū)⒅付夸浿械奈募蟼鱨ocalPath到 Azure Blob 存儲(chǔ)容器。問題是文件沒有放置在容器的根目錄中,而是創(chuàng)建了與變量定義的文件路徑匹配的文件夾localPath。string localPath = @"C:\example\path\to\files";生成的 blob 容器如下所示。.+-- example| +-- path| +-- to| +-- files| +-- file1.json| +-- file2.json| +-- file3.json| +-- file4.json| +-- file5.json需要對(duì)下面的代碼進(jìn)行哪些更改,以便將文件移動(dòng)到容器的根目錄,而不是移動(dòng)到與 匹配的文件夾結(jié)構(gòu)中l(wèi)ocalPath?程序.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 存儲(chǔ)容器的根目錄
慕尼黑8549860
2024-01-20 21:02:22