可以通过多种方式来对Azure Blob进行操作。在此我们介绍通过VS的客户端及代码两种方式来操作Blob。

一、通过VS来操作Blob.

1.首先下载publish settings 文件:打开“https://manage.windowsazure.cn/publishsettings/index”,登陆China Azure,下载publish Settings文件到本地。

2.      打开Visual Studio, 选择
View -> Server Explorer

3.    在左侧面板,右键点击Windows Azure, 选择Manage
Subscriptions;

4.       在Manage Microsoft Azure Subscriptions中点击Certificates(0)选项卡。 点击Import,把第一步下载的Publish settings文件导入

5.展开Azure->Storage下的存储(我的存储实例为terryteststorage)
       

6.  点击存储实例下的Blobs即可查看此存储下有哪些Container及每个Container下存储的数据信息。

7.   上传文件到指定的Container。先在Blobs上右击,然后选择Create Blob Container,然后弹出创建Container页面。

8.   输入Container名称”test1”,然后点击OK按钮。

9.至此,test1已创建成功,test1中未有任何数据

10.    上传文件到test1中。点击页面上方的Upload Blob按钮

11.     在弹出的上传控件中选择要上传的文件后,单击OK按钮。

12.    至此,选择的文件已上传到test1中。

二、通过 Storage API来创建Container、显示Container及上传文件到指定的Container.

1. 创建AzureBlockStorage类型工程, 输入工程名称” DataBlobStorageExample”,点击OK.

2.    具体代码实例如下:

static StorageCredentials credentials = new StorageCredentials("terryteststorage", "0HnFgkllVNf7m0dTBM/U7hbC96o/YUVH ==");

        static CloudStorageAccount storageAccount = new CloudStorageAccount(credentials,new Uri("https://terryteststorage.blob.core.chinacloudapi.cn/"),
            new Uri("https://terryteststorage.queue.core.chinacloudapi.cn/"),
            new Uri("https://terryteststorage.table.core.chinacloudapi.cn/"),null);         static void Main(string[] args)
        {
            
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();   
            //create container
            CloudBlobContainer container = blobClient.GetContainerReference("container1");
            container.CreateIfNotExists();             //List containers
            List<CloudBlobContainer> containers ;
            if (ListContainers(out containers))
            {              
                if (containers != null)
                {
                    foreach (CloudBlobContainer container2 in containers)
                    {
                        Console.Write(container2.Name + " ");
                    }
                    Console.WriteLine();
                }
            }         
                        //put file to blob
            PutBlob("container1", "blob1.txt", "This is a text blob!");   
}   public static bool ListContainers(out List<CloudBlobContainer> containerList)
        {
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            containerList = new List<CloudBlobContainer>();
            try
            {
                IEnumerable<CloudBlobContainer> containers = blobClient.ListContainers();
                if (containers != null)
                {
                    containerList.AddRange(containers);
                }
                return true;
            }
            catch (Exception ex)
            {
                               throw;
            }
        }   public static  bool PutBlob(string containerName, string blobName, string content)
        {
            try
            {
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer container = blobClient.GetContainerReference(containerName);
                ICloudBlob blob = container.GetBlockBlobReference(blobName);
                string filePath = @"D:\Terry\blocktest.txt";
                blob.UploadFromFile(filePath, FileMode.OpenOrCreate);
                return true;
            }
            catch (Exception ex)
            {                 Console.WriteLine("error in Putblock");
            }
        }

3. 运行结果

使用Azure Blob存储的更多相关文章

  1. 通过 PHP 连接China Azure Blob 存储

    问题说明 Azure Blob 存储是一种将非结构化数据作为对象/Blob存储在云中的服务.Blob存储可以存储任何类型的文本或二进制数据,例如文档.媒体文件或应用程序安装程序.Blob存储也称为对象 ...

  2. ASP.NET Core 2.0中的Azure Blob存储

    问题 如何在ASP.NET Core中使用Azure Blob存储 解 创建一个类库并添加NuGet包 - WindowsAzure.Storage 添加一个类来封装设置, publicclass A ...

  3. Azure Blob 存储简介

    Azure Blob 存储是 Microsoft 提供的适用于云的对象存储解决方案. Blob 存储最适合存储巨量的非结构化数据. 非结构化数据是不遵循特定数据模型或定义(如文本或二进制数据)的数据. ...

  4. Azure Blob存储更改缓存时间

    Azure的Blob存储可以作为Http的服务来使用.很多客户已经把Blob作为图片存储的服务,这样稍作代码的修改,解决了图片服务器带宽.性能等多种问题. 但同时问题也出现了:在传统Http的服务中很 ...

  5. .NET 使用 Azure Blob 存储图片或文件

    使用的是VS2017 一.先使用 NuGet 获取这两个包. 执行以下步骤: 在“解决方案资源管理器”中,右键单击你的项目并选择“管理 NuGet 包”. 1.在线搜索“WindowsAzure.St ...

  6. Azure Storage 系列(二) .NET Core Web 项目中操作 Blob 存储

    一,引言 上一篇文章,我们介绍到在实际项目中系统会产生大量的日志文件,用户上传的头像等等,同时也介绍到可以使用Azure Blob Storage 来存储项目中的一些日志文件,用户头像,用户视频等等. ...

  7. 微软开放技术发布开源 Jenkins 插件以将 Windows Azure Blob 服务用的开作存储库

     发布于 2014-02-10 作者 陈 忠岳 持续集成 (CI) 的历史源远流长, 其宗旨在于软件团队在敏捷环境中不断将他们的工作整合为持续构建.管理 CI 进程的工具已存在一段时间.过去几年中 ...

  8. AzCopy – 上传/下载 Windows Azure Blob 文件

    在我们收到的请求中,有一个频繁出现的请求是提供一种能在 Windows Azure Blob 存储与其本地文件系统之间轻松上传或下载文件的方法.一年半前, 我们很高兴地发布了 AzCopy, Wind ...

  9. 使用 Azure 创建存储和检索文件

    本指南将以循序渐进的方式帮助您使用 Azure 将文件存储到云中.我们将逐一介绍如何创建存储账户.创建容器.上传文件.检索文件和删除文件.在本教程中完成的所有操作均符合 1 元试用条件. 本指南将以循 ...

随机推荐

  1. LintCode Interleaving String

    Given three strings: s1, s2, s3, determine whether s3 is formed by the interleaving of s1 and s2. Ex ...

  2. HTML5新标签video在iOS上默认全屏播放

    今天做一个app时发现一个问题,应用html5中的video标签加载视频,在Android手机上默认播放大小,但是换成iPhone手机上出问题了,默认弹出全屏播放,查找了好多论坛,都没有谈论这个的.然 ...

  3. 前端基础 JavaScript~~~ 数据处理 奇技淫巧!!!!!!

    常用的JS数据处理手段      2016-09-21          17:40:07 1.   number类型  数组中取出里面的最大/最小值: // 数组中取出 最小值 [数值] var n ...

  4. 结对编程--基于android平台的黄金点游戏(2.0版本)

    在昨天上传完博客之后发现一个重大的bug...故在此推出2.0版本. 博文详情见:http://www.cnblogs.com/RayShea/p/5372398.html coding地址:http ...

  5. 跟我学Windows Azure 一 创建Windows Azure试用账号

    我在网上看了很多教程,很大部分都是申请的是国外或者是香港的试用账号,而国内是由世纪互联所代理的,他的申请方式与VS2013的部署设置或多或少还是有些出入,这里我先跟大家一起过一下,在国内如何申请一个w ...

  6. delegate用法

    一般来说 delegate 可以申明一个delegate类型  比如 public delegate funa(object b) 然后使用的时候申明 funa 作为类型  new funa(回调函数 ...

  7. Python>>>创建一个简单的3D场景

    首先安装PyOpengl pip install PyOpenGL PyOpenGL_accelerate

  8. 改进:js修改iOS微信浏览器的title

    问题简介 前端入门没多久,可能连入门也不算,最近网上流行各自书籍改名,什么<前端开发,从入门到放弃>,<Android开发,从入门到改行>之类的,程序员真是个爱自嘲的群体,但我 ...

  9. Beta版本冲刺——day2

    No Bug 031402401鲍亮 031402402曹鑫杰 031402403常松 031402412林淋 031402418汪培侨 031402426许秋鑫 站立式会议 培侨走的第5天,想他~( ...

  10. Oracle 使用SqlPlus管理

    Oracle 使用SqlPlus 安装,一键安装,很简单.安装过程,一定要记住密码 一.登陆sqlplus 连接本地服务器,可以直接,打开cmd: 可以直接不用登陆,如果登陆需要输入用户名.密码. s ...