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><addname="Azure"providerName="System.StorageModel.WindowsAzure.AzureProvider, Cloud4Net.Azure"connectionString="YourAzureConnectionString"/><addname="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><sectionGroupname="system.storageModel"><sectionname="blobs"type="System.StorageModel.Configuration.BlobStorageSection, Cloud4Net.Abstractions"/></sectionGroup></configSections><system.storageModel><!-- specify the default provider for blobs --><blobsdefaultProvider="Azure"><!-- containers registered hereunder will be created on startup if they not already exist --><containername="pictures"/><containername="videos"/><!-- you can assign a different provider to each container (provider attribute) --><containername="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 | Image may be NSFW. Clik here to view. ![]() | Image may be NSFW. Clik here to view. ![]() | Image may be NSFW. Clik here to view. ![]() | Image may be NSFW. Clik here to view. ![]() |
Create a blob container | Image may be NSFW. Clik here to view. ![]() | Image may be NSFW. Clik here to view. ![]() | Image may be NSFW. Clik here to view. ![]() | Image may be NSFW. Clik here to view. ![]() |
Delete a blob container | Image may be NSFW. Clik here to view. ![]() | Image may be NSFW. Clik here to view. ![]() | Image may be NSFW. Clik here to view. ![]() | Image may be NSFW. Clik here to view. ![]() |
Does a blob container exists ? | Image may be NSFW. Clik here to view. ![]() | Image may be NSFW. Clik here to view. ![]() | Image may be NSFW. Clik here to view. ![]() | Image may be NSFW. Clik here to view. ![]() |
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 existvar exist = provider.Containers["container-name"].Exist;