【发布时间】:2019-10-08 20:21:52
【问题描述】:
我编写了一个小控制台应用程序,将本地计算机上文件夹中的文件上传到 Azure blob 存储,我的问题是代码编译并运行没有错误,但我没有得到预期的结果。
我希望 FolderPath 中的所有文件都上传到容器,如果容器不存在来创建它,但它永远不会被创建,控制台告诉我所有内容都在上传。那时我对代码的期望可能不正确。
using System;
using System.IO;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Blob.Protocol;
namespace AzureBlobs
{
class Program
{
const string StorageAccountName = "cs72e88a177daeax40edxbf2";
const string StorageAccountKey = "[ACCOUNT KEY]";
const string FolderPath = @"[LOCAL FILE PATH]";
static void Main()
{
var storageAccount = new CloudStorageAccount(new StorageCredentials(StorageAccountName, StorageAccountKey), true);
var blobclient = storageAccount.CreateCloudBlobClient();
var container = blobclient.GetContainerReference("newcontainer");
container.CreateIfNotExistsAsync();
container.SetPermissionsAsync(new BlobContainerPermissions()
{
PublicAccess = BlobContainerPublicAccessType.Blob
});
foreach( var filePath in Directory.GetFiles(FolderPath, "*.*", SearchOption.AllDirectories))
{
var blob = container.GetBlockBlobReference(filePath);
blob.UploadFromFileAsync(filePath);
Console.WriteLine("Uploaded {0}", filePath);
}
Console.WriteLine("Donzos!");
}
}
}
【问题讨论】:
标签: c# azure-blob-storage