我想將文件上傳到Windows Azure blob存儲。根據我的理解,您可以將文件上傳到類似於子目錄的文件中。我要上傳文件到BLOB使得文件基本上是駐留在/TestContainer/subDirectory1/subDirectory2/file.png
在Windows Azure Blob存儲中使用子目錄
// Setup the Windows Aure blob client
CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting("BlobStorage");
CloudBlobClient client = storageAccount.CreateCloudBlobClient();
// Retrieve the TestContainer container from blob storage
CloudBlobContainer container = client.GetContainerReference("TestContainer");
if (container.CreateIfNotExist())
container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
// Setup the blob
CloudBlob blob = container.GetBlobReference("");
// Create the meta data for the blob
NameValueCollection metadata = new NameValueCollection();
metadata["id"] = fileID.ToString();
blob.Metadata.Add(metadata);
// Store the blob
byte[] bytes = GetFileBytes();
blob.UploadByteArray(bytes);
如何上傳與目錄結構的文件?鏈接here提到有辦法做到這一點。但是,它並沒有告訴你如何去做。
謝謝!