HomeDev GuideRecipesAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

BLOB storage and providers

Explains the concept and usage of BLOBs (Binary Large Objects) in Optimizely.

BLOB providers store large amounts of binary data in an optimized, cost-effective solution such as cloud storage instead of a database. Use BLOB providers to offload media and file storage from the database, improving performance and scalability.

BLOB providers

Optimizely supports BLOB storage of assets using a provider-based setup and includes a built-in file BLOB provider. The following options are available:

  • Customized BLOB provider – Create a provider for your specific hosting environment. BLOB providers for Microsoft Azure and Amazon Web Services are available from the Optimizely NuGet feed.
  • Built-in BLOB provider – Optimizely includes an implementation for Microsoft Azure. An open-source example for Amazon is also available. This example is not actively maintained or updated to CMS 13 but serves as inspiration for an implementation on Amazon or another storage backend.

BLOB architecture

Understanding BLOB architecture helps you work with containers, unique identifiers, and the provider API effectively.

A provider stores and associates a data stream with a unique identifier. BLOBs are grouped into containers: a logical name for a set of BLOBs that you delete with a single API call. The unique identifier is exposed as a URI in the format epi.fx.blob://[provider]/[container]/[blob] to store a reference to a BLOB in a database.

Most API methods return a reference even when the actual BLOB does not exist because accessing a cloud service on every call is too costly. For example, GetBlob returns a reference, and the caller tracks BLOB identifiers.

The following example shows how to use a BLOB provider.

public void ReadWriteBlobs() {
  var blobFactory = ServiceLocator.Current.GetInstance<IBlobFactory>();

  //Define a container
  var container = Blob.GetContainerIdentifier(Guid.NewGuid());

  //Uploading a file to a blob
  var blob1 = blobFactory.CreateBlob(container, ".png");
  using(var fs = new FileStream("c:\\myfile.png", FileMode.Open)) {
    blob1.Write(fs);
  }

  //Writing custom data to a blob
  var blob2 = blobFactory.CreateBlob(container, ".txt");
  using(var s = blob2.OpenWrite()) {
    var w = new StreamWriter(s);
    w.WriteLine("Hello World!");
    w.Flush();
  }

  //Reading from a blob based on ID
  var blobID = blob2.ID;
  var blob3 = blobFactory.GetBlob(blobID);
  using(var s = blob3.OpenRead()) {
    var helloWorld = new StreamReader(s).ReadToEnd();
  }

  //Delete single blob
  blobFactory.Delete(blobID);

  //Delete container
  blobFactory.Delete(container);
}
📘

Note

Deleting a container under the website root with the FileBlob provider leaves empty folders under the website root. The Azure and Amazon providers delete the containers. For information about handling media in the assets pane, see Media examples.