C # Azure Storage-blob

Source: Internet
Author: User
Tags microsoft website

1. Preface

This article was written according to the Azure documentation and I did the verification.

If you want to download the demo from Microsoft website, go to GitHub https://github.com/Azure-Samples/storage-blob-dotnet-getting-started

2. Introduction

Azure Blob is a service that stores a lot of space and can allow storage and access over HTTP or HTTPS. A blob is a property that has public and private properties. The public is a link that everyone can see, and the private is to access the resource through the secret key.

BLOBs can be stored:

1) Images or document pointing to a folder

2) Save File

3) Video and audio

4) Backup and recovery of stored data, disaster recovery and archiving

5) Analytics by a locally stored data or Azure managed service

3. Concept

1) Container container:

A container can contain many blobs, and an account can contain a lot of containers containers. Please note that the container name is lowercase.

2) Blob:

A BLOB is the property and size of a file. Azure storage blobs consists of three types: block BLOBs, page blobs, append blobs.

Block BLOBs: Stores text and binary files, such as documents and media type files.

Append blobs: is similar to block blobs, but it is an operation optimized, so it is used for logging operations. A simple block blob or append blob can contain 5,000 blocks, up to 4MB per file, with a maximum size of 194GB (4mb*50000)

Page blobs: Up to 1TB, is an operation that can read and write.

4. Code Start

1) Create a storage account

For steps to create a store, refer to


The 3rd largest point in

2) Import the package and enter the following command on the package Manager:

Install-package Windowsazure.storage

Install-package Microsoft.WindowsAzure.ConfigurationManager

2) Establish a connection

              string"Defaultendpointsprotocol=https; Accountname=ceslighttest; accountkey=cp3jxyfxu6xhv18ovqw2q7urhohxhm9guwl6ueltbwd9nxxxxxxxxxxxxxx; endpointsuffix=core.chinacloudapi.cn";                 // Establish a connection                Cloudstorageaccount Storageaccount = cloudstorageaccount.parse (connstr);                = Storageaccount.createcloudblobclient ();

3) Create a container

             //  create container, presence or absence                Cloudblobcontainer container = blobclient.getcontainerreference ("testuimageblobcontainercompanyname ");              Container. Createifnotexists ();

4) Set permissions

The container is private by default, meaning that you want to specify a key to download the picture. If you want to set the picture to be downloaded anywhere, please set it to public

                // container default is private, meaning to specify key to download pictures. If you want to set the picture to be downloaded anywhere, please set itto public                container. SetPermissions (new blobcontainerpermissions {publicaccess = Blobcontainerpublicaccesstype.blob});

5) Create the file and upload the local file

             //  Create a file name and replace                it if you have the same file name Cloudblockblob Blockblob = container. Getblockblobreference ("23.jpg");                 // uploading local Files                using (var fileStream = System.IO.File.OpenRead (@ "E:\23.jpg"))                {                    blockblob.uploadfromstream (fileStream);                }

6) Show all blobs files inside the container

               //output file size vs. path URI                foreach(Ilistblobitem IteminchContainer. Listblobs (NULL,false))                {                    if(item. GetType () = =typeof(Cloudblockblob)) {Cloudblockblob blob=(CLOUDBLOCKBLOB) item; R+=string. Format ("Block blob of length {0}: {1}", Blob. Properties.length, Blob.                    Uri); }                    Else if(item. GetType () = =typeof(Cloudpageblob)) {Cloudpageblob Pageblob=(CLOUDPAGEBLOB) item; R+=string. Format ("Page blob of length {0}: {1}", PageBlob.Properties.Length, Pageblob.uri); }                    Else if(item. GetType () = =typeof(cloudblobdirectory)) {Cloudblobdirectory directory=(cloudblobdirectory) item; R+=string. Format ("Directory: {0}", directory.                    Uri); }                }

C # Azure Storage-blob

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.