【发布时间】:2012-12-05 11:13:09
【问题描述】:
在文章How to use the Windows Azure Blob Storage Service in .NET 中,以下代码用于演示如何上传文件
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");
// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))
{
blockBlob.UploadFromStream(fileStream);
}
如果您有一个长时间运行的服务,它接受文件并将它们存储在 blob 存储中,您会每次都执行所有这些步骤吗?或者您可能有一个引用了多个请求使用的blockBlob 的类?从多个请求中缓存和使用多少(如果有的话)是可以的? (我猜这意味着线程)
【问题讨论】:
标签: azure connection azure-storage