Azure Flavor for the Sharepoint Media Component
Some time ago I wrote about a Media Processing Component for Sharepoint that I was working on. It is a Media Assets list for Sharepoint that lets you choose where to store the blob files. It provides also intelligence for encoding videos, generating thumbnail and poster images, obtaining media metadata, etc. On that first post the component was explained in detail, with the original 3 storage flavors: Sharepoint list, Virtual Directoy or FTP. The storage manager is extensible, so a new flavor was added later that enabled to store the media files on the cloud, in particular to AmazonS3. Today I’m going to talk about a new cloud flavor based on Azure Blob Storage.
Windows Azure Blob storage is a service for storing large amounts of unstructured data that can be accessed from anywhere in the world via HTTP or HTTPS. This kind of storage is special for storing large amounts of unstructured text or binary data such as video, audio and images. You can find documentation here on how to create a Windows Azure Storage Account and access it programmatically.
For the Media Processing Component I just needed to create a class (AzureStorageManager) that implemented the IAssetStorageManager interface. The interface has the methods to save and delete files from the external storage. It also needs four configuration parameters to be passed to its constructor:
- AccountName: Name of the account that will be used to authenticate to the Blob Storage
- AccountKey: Key that will be used to authenticate to the Blob Storage
- BlobEndpoint: URL of the Blob endpoint, like http://someaccount.blob.core.windows.net
- Container: Name of a container to store your application’s media files.
For example, this is the code required to upload a file to an Azure Blob Storage:
- public string Save(System.IO.FileInfo file)
- {
- //Create service client for credentialed access to the Blob service.
- CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint, new StorageCredentialsAccountAndKey(accountName, accountKey));
- //Get a reference to a container, which may or may not exist.
- CloudBlobContainer container = blobClient.GetContainerReference(containerAddress);
- //Create a new container, if it does not exist
- container.CreateIfNotExist();
- //Get a reference to a blob, which may or may not exist.
- CloudBlob blob = container.GetBlobReference(file.Name);
- //Upload content to the blob, which will create the blob if it does not already exist.
- blob.UploadFile(file.FullName);
- return blob.Uri.ToString();
- }
You can download the complete code for the Media Component with all the storage options from gitgub.