Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Loading...
Area: Optimizely CMS
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

BLOB (Binary Large Object) providers is a framework designed to store large amounts of binary data in a more optimized and cost-effective solution such as cloud storage, instead of in the 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:

  • Built-in BLOB provider. EPiServer has a built-in BLOB provider for media files such as images, videos and documents. By default this provider will store files on local disc or a file share which will be defined during installation.
  • Customized BLOB provider. You can also develop and configure your own customized BLOB provider for your specific hosting environment. As an example, BLOB providers for Microsoft Azure and  Amazon Web Services are available via the EPiServer NuGet feed.
     

Architecture

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, that for example can be deleted using a single API call. The unique identifier is exposed as an URI in the format epi.fx.blob://[provider]/[container]/[blob]] to make it easy to store a reference to a BLOB in for example a database.

Most methods in the API will always return a reference even though the actual BLOB does not exists, since it would be too costly to go out to a cloud service everytime, 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:

C#
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 that when deleting a container under the website root, if you use the FileBlob provider, it will by default leave empty folders under the website root. If you use the Azure or the Amazon provider, it will by default delete the containers. For more information about how to handle media in the assets pane, refer to Working with media.  

Configuring a custom BLOB provider

Add a blob element to the episerver.framework section in the web.config to define a custom provider:

XML
<episerver.framework>
    <blob defaultProvider="myProvider">
        <providers>
            <add name="myProvider" type="MyAssembly.Provider, MyAssembly" />
        </providers>
    </blob>
</episerver.framework>

See also

Do you find this information helpful? Please log in to provide feedback.

Last updated: Jul 09, 2014

Recommended reading