在如何在 .NET 中使用 Windows Azure Blob 存储服务一文中,以下代码用于演示如何上传文件
// 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
了多个请求使用的类?从多个请求中缓存和使用多少(如果有的话)是可以的?(我猜这意味着线程)