Azure存储模拟器 - 如何指定分层路径?

时间:2015-08-31 23:59:23

标签: azure emulation azure-storage azure-storage-blobs

我正在使用Azure存储模拟器4.1.0.0和VS 2013。

如何从开发框上传文件并在Azure Blob存储上指定分层路径?

我正在本地开发VS 2013& Azure存储模拟器4.1.0.0。 我想上传文件,但指定Blob的文件分层路径。

const string ImageToUpload = @"C:\Users\Me\Documents\Visual Studio 2013\Projects\AzureCloudService1\DataBlobStorage1\HelloWorld2.png"; 
CloudBlockBlob blockBlob = container.GetBlockBlobReference(ImageToUpload);
await blockBlob.UploadFromFileAsync(ImageToUpload, FileMode.Open).ConfigureAwait(configureawait);

此代码确实上传了文件,但最终将源的物理路径存储到文件中。如何为Azure Blob存储指定所需的分层路径?

THX!

2 个答案:

答案 0 :(得分:1)

想象一下,您希望容器中的路径为AzureCloudService1\DataBlobStorage1\HelloWorld2.png,这就是您必须要做的事情:

CloudBlockBlob blockBlob = container.GetBlockBlobReference("AzureCloudService1/DataBlobStorage1/HelloWorld2.png");

答案 1 :(得分:0)

Ah... GetBlockBlobReference is what sets the blob name, and it can be named as desired. The actual file can be read into a fileStream from some other physical location and uploaded into the blob, like so:

    string fileName = HttpContext.Current.Server.MapPath("~/App_Data/Clients/Clientname/" + "HelloWorld.png");
    CloudBlockBlob blockBlob = container.GetBlockBlobReference(@"Clients\ClientName");
    using (var fileStream = File.OpenRead(fileName))
    {
        await blockBlob.UploadFromStreamAsync(fileStream);
    }