Working withs Blobs

Resource Model

  • Blobs are web resources (e.g. files) stored on one or more cloud provider datacenters. They follow REST principles (e.g. GET/PUT, ETag, LastModified).
  • They can be read or written.
  • They are grouped into named Containers
  • They have a unique path inside their container. Paths can be a hierarchy of folders
  • Blobs have Metadata (name/value collection pairs), which can be read/written independently of their content.

Configuration

- At minimum you must define your provider connection string. See ConnectionStrings
<configuration>
  <connectionStrings>
    <add name="Azure" providerName="System.StorageModel.WindowsAzure.AzureProvider, Cloud4Net.Azure" connectionString="YourAzureConnectionString"/>
    <add name="AWS" providerName="System.StorageModel.AWS.AWSProvider, Cloud4Net.AWS" connectionString="YourAWSConnectionString"/>
  </connectionStrings>
</configuration>

- You can also define static blob containers. These containers will be automatically created on startup if they do not already exist.
Warning: container names and blob paths have restrictions of their associated provider (most of the time a container name must comply with a DNS subdomain rules for CDN exposure).
<configuration>
  <configSections>
    <sectionGroup name="system.storageModel">
      <section name="blobs" type="System.StorageModel.Configuration.BlobStorageSection, Cloud4Net.Abstractions" />
    </sectionGroup>
  </configSections>
  <system.storageModel>
    <!-- specify the default provider for blobs -->
    <blobs defaultProvider="Azure">
      <!-- containers registered hereunder will be created on startup if they not already exist -->
      <container name="pictures"/>
      <container name="videos"/>

      <!-- you can assign a different provider to each container (provider attribute) -->
      <container name="cdn-images" provider="AWS"/>
    </blobs>
  </system.storagemodel>
</configuration>

Code Model

  • You can code against the generic model using IBlobProvider, IBlobContainer and IBlobSpec interfaces:
BlobStorage.Containers["test-container"].Blobs["test-blob"].DeleteIfExist();
  • You can also code against the provider-specific model (AzureProvider, AWSBlobContainer, etc.) to get provider-specific features:
var provider = Storage.GetProvider<AzureProvider>("Azure");
var container = provider.Containers["test-container"];
container.MetaData["data1"] = "value1";
container.UpdateMetaData(); // container metadata feature is specific to Azure Blob Storage

How-to

How-to Azure AWS NTFS Cache
Get a specific provider from configuration Supported Supported Supported Supported
Create a blob container Supported Supported Supported Supported
Delete a blob container Supported Supported Supported Supported
Does a blob container exists ? Supported Supported Supported Supported


Get a specific blob provider from config


using System.StorageModel;
var provider = Storage.GetProvider<IBlobProvider>("Name");

Create a blob container


// create the specified container (throws an exception if it already exist)
provider.Containers["container-name"].Create();
// create the specified container (without throwing an exception)
provider.Containers["container-name"].CreateIfNotExist();

Delete a blob container


// delete the specified container (throws an exception if it does not exist)
provider.Containers["container-name"].Delete();
// delete the specified container (without throwing an exception)
provider.Containers["container-name"].DeleteIfExist();

Does a blob container exist ?


// test if the specified container exist
var exist = provider.Containers["container-name"].Exist;
implementation note: for performance purpose, the Exist property is evaluated once per container object (e.g. if you test it multiple times on the same object, the provider will not check again). To check multiple time if a container exist, get another reference to the container (by calling providers.Containers["container-name"] again)

Last edited May 9, 2010 at 9:43 AM by JazBee, version 13

Comments

No comments yet.