Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
BLOB (Binary Large Object) 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 in a database. The Episerver platform supports BLOB storage of assets using a provider-based setup, and has a built-in file BLOB provider. You have the following options:
A provider is responsible for storing a stream of data and associate it with a unique identifier. BLOBs are grouped into containers which is 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 it is assumed that the caller keeps track of BLOB identifiers.
The following example shows how to use a BLOB provider:
public void ReadWriteBlobs()
{
//Define a container
var container = Blob.GetContainerIdentifier(Guid.NewGuid());
//Uploading a file to a blob
var blob1 = BlobFactory.Instance.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.Instance.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.Instance.GetBlob(blobID);
using (var s = blob3.OpenRead())
{
var helloWorld = new StreamReader(s).ReadToEnd();
}
//Delete single blob
BlobFactory.Instance.Delete(blobID);
//Delete container
BlobFactory.Instance.Delete(container);
}
Note: When you delete a container under the website root, if you use the FileBlob provider, 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 Working with media.
Add a blob element to the episerver.framework section in web.config to define a custom provider:
<episerver.framework>
<blob defaultProvider="myProvider">
<providers>
<add name="myProvider" type="MyAssembly.Provider, MyAssembly" />
</providers>
</blob>
</episerver.framework>
Related topics
Last updated: Feb 23, 2015