Windows Azure Storage (25) Azure Append Blob

简介:

  《Windows Azure Platform 系列文章目录

  

  在笔者之前的文章中,我们介绍了Azure Blob 有两种:Block Blob和Page Blob。

  在这里笔者介绍Blob的第三种:Append Blob。

 

  概念:

  1.Append Blob概念类似于Block Blob,因为都是由块组成的

  2.单个Block Blob可以包含最多50000个块,每个块最大100MB,总大小大约4.75TB (100MB * 50000)。

  3.Append Blob针对追加操作进行了优化,特别适合与日志记录方案

  4.Append Blob可以包含最多50000个块,每个块最大4MB。总大小约为195GB

  5.Append Blob不支持修改和删除,每个对Append Blob的操作,都会追加到Append Blob的末尾。

 

  我们这里写一个.NET的Sample Code:

复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.WindowsAzure.Storage;
using System.Configuration;
using Microsoft.WindowsAzure.Storage.Blob;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureStorageConnectionString"]);
            CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
            
            //Container Name必须为小写
            CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("appendblobcontainer");
            cloudBlobContainer.CreateIfNotExists();

            CloudAppendBlob cloudAppendBlob = cloudBlobContainer.GetAppendBlobReference("helloworld.txt");

            //如果不存在,则创建该文件
            if(!cloudAppendBlob.Exists())
            { 
                cloudAppendBlob.CreateOrReplace();
            }

            var tasks = new Task[100];
            for (int i = 0; i < 100; i++)
            {
                var message = string.Format("Appending log number {0} to an append blob.\r\n", i);

                var bytes = Encoding.UTF8.GetBytes(message);

                var stream = new MemoryStream(bytes);

                tasks[i] = cloudAppendBlob.AppendBlockAsync(stream);
            }

            Task.WaitAll(tasks);

            string appendBlobContent = cloudAppendBlob.DownloadText();
        }
    }
}
复制代码

  如果我们执行代码两次,然后通过Azure Storage Explorer查看这个TXT文件,就可以看到文件被追加到Azure Append Blob里面了。


本文转自Azure Lei Zhang博客园博客,原文链接:http://www.cnblogs.com/threestone/p/7904706.html,如需转载请自行联系原作者


目录
相关文章
|
3月前
|
安全 Windows
【Azure Cloud Service】在Windows系统中抓取网络包 ( 不需要另外安全抓包工具)
通常,在生产环境中,为了保证系统环境的安全和纯粹,是不建议安装其它软件或排查工具(如果可以安装,也是需要走审批流程)。 本文将介绍一种,不用安装Wireshark / tcpdump 等工具,使用Windows系统自带的 netsh trace 命令来获取网络包的步骤
103 32
|
3月前
|
C# Windows
【Azure App Service】在App Service for Windows上验证能占用的内存最大值
根据以上测验,当使用App Service内存没有达到预期的值,且应用异常日志出现OutOfMemory时,就需要检查Platform的设置是否位64bit。
63 11
|
6月前
|
网络安全 API 数据安全/隐私保护
【Azure App Service】.NET代码实验App Service应用中获取TLS/SSL 证书 (App Service Windows)
【Azure App Service】.NET代码实验App Service应用中获取TLS/SSL 证书 (App Service Windows)
|
6月前
|
Shell PHP Windows
【Azure App Service】Web Job 报错 UNC paths are not supported. Defaulting to Windows directory.
【Azure App Service】Web Job 报错 UNC paths are not supported. Defaulting to Windows directory.
|
6月前
|
PHP Windows
【Azure App Service for Windows】 PHP应用出现500 : The page cannot be displayed because an internal server error has occurred. 错误
【Azure App Service for Windows】 PHP应用出现500 : The page cannot be displayed because an internal server error has occurred. 错误
|
6月前
|
存储 Linux Windows
【应用服务 App Service】App Service For Windows 如何挂载Storage Account File Share 示例
【应用服务 App Service】App Service For Windows 如何挂载Storage Account File Share 示例
|
6月前
|
Linux C++ Windows
【Azure 应用服务】Azure App Service(Windows)环境中如何让.NET应用调用SAP NetWeaver RFC函数
【Azure 应用服务】Azure App Service(Windows)环境中如何让.NET应用调用SAP NetWeaver RFC函数
【Azure 应用服务】Azure App Service(Windows)环境中如何让.NET应用调用SAP NetWeaver RFC函数
|
6月前
|
应用服务中间件 nginx Windows
【Azure 应用服务】在App Service for Windows中实现反向代理
【Azure 应用服务】在App Service for Windows中实现反向代理
|
6月前
|
安全 Windows
【Azure 云服务】当Windows系统发布新的安全漏洞后,如何查看Azure云服务(Cloud Service)的实例是否也更新了安全补丁呢?
【Azure 云服务】当Windows系统发布新的安全漏洞后,如何查看Azure云服务(Cloud Service)的实例是否也更新了安全补丁呢?
|
6月前
|
PHP 开发工具 git
【Azure 应用服务】在 App Service for Windows 中自定义 PHP 版本的方法
【Azure 应用服务】在 App Service for Windows 中自定义 PHP 版本的方法