BLOB storage and providers
Explains the concept and usage of BLOBs (Binary Large Objects) in Optimizely.
BLOB providers are a framework designed to store large amounts of binary data in an optimized and cost-effective solution, such as cloud storage instead of a database.
BLOB providers
The Optimizely platform supports BLOB storage of assets using a provider-based setup and has a built-in file BLOB provider. You have the following options:
- Customized BLOB provider for your specific hosting environment, such as BLOB providers for Microsoft Azure and Amazon Web Services, available from the Optimizely NuGet feed.
- Built-in BLOB provider for your specific hosting environment. Optimizely provides an implementation for Microsoft Azure. There are also an open source example for Amazon. This example is not actively maintained and not updated to CMS 13, but can serve as inspiration for an implementation on Amazon or other storage backend.
BLOB architecture
A provider is responsible for storing and associating a data stream with a unique identifier. BLOBs are grouped into containers, a logical name for a set of BLOBs, which you can 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 methods in the API return a reference even though the actual BLOB does not exist because it would be too costly to access a cloud service every time; for example, a call to GetBlob is made, and the caller is assumed to keep track of BLOB identifiers.
The example below 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);
}
NoteWhen you delete a container under the website root, if you use the
FileBlobprovider, it leaves empty folders under the website root. If you use the Azure or the Amazon provider, it deletes the containers. For information about handling media in the assets pane, see Media examples.
Updated 3 days ago
