Skip to content

Azure Media Storage (OrchardCore.Media.Azure)

The Azure Media Storage feature enables support for storing assets in Microsoft Azure Blob Storage.

The feature replaces the default App_Data file based media store with an Azure Media Storage Provider.

Media is still served by the Orchard Core web site, and the Media Cache module takes responsibility for fetching media, on the fly, from the Azure Blob Storage Container.

This allows the Azure Media Storage feature to support image resizing on the fly through integration with ImageSharp.Web.

The url generated by the AssetUrl helpers, points to the Orchard Core web site.

Configuration

The following configuration values are used by default and can be customized:

{
   "OrchardCore": {
    "OrchardCore_Media_Azure": {
      // Set to your Azure Storage account connection string.
      "ConnectionString": "", 
      // Set to the Azure Blob container name. A container name must be a valid DNS name and conform to Azure container naming rules eg. lowercase only.
      "ContainerName": "somecontainer",
      // Optionally, set to a path to store media in a subdirectory inside your container.
      "BasePath": "some/base/path",
      "CreateContainer": true
    }
  }
}

Refer also to the Configuration Section, and the Media Section for other Media related configuration settings.

If the CreateContainer option is set to true an activating event will check on Startup for a valid connection string, and test that the container exists, creating if it does not. Set CreateContainer to false to disable this check if your container already exists.

If these are not present in appSettings.json, it will not enable the feature, and report an error message in the log file.

Templating Configuration

Optionally you may use liquid templating to further configure Azure Media Storage, perhaps creating a container per tenant, or a single container with a base path per tenant.

The ShellSettings property is made available to the liquid template. The ContainerName property and the BasePath property are the only templatable properties.

Note

When templating the ContainerName using {{ ShellSettings.Name }}, the tenant's name will be automatically lowercased, however, you must also make sure the ContainerName conforms to other Azure Blob naming conventions as set out in Azure's documentation.

Configuring a container per tenant

{
  "OrchardCore": {
    "OrchardCore_Media_Azure": {
      // Set to your Azure Storage account connection string.
      "ConnectionString": "", 
      // Optionally configure with liquid. A container name must be a valid DNS name and conform to Azure container naming rules eg. lowercase only.
      "ContainerName": "{{ ShellSettings.Name }}-media",
      // Optionally configure with liquid.
      "BasePath": "Media",
      "CreateContainer": true
    }
  }
}

Configuring a single container, with a base folder per tenant

{
  "OrchardCore": {
    "OrchardCore_Media_Azure": {
      // Set to your Azure Storage account connection string.
      "ConnectionString": "", 
      // Optionally configure with liquid. A container name must be a valid DNS name and conform to Azure container naming rules eg. lowercase only.
      "ContainerName": "somecontainer",
      // Optionally configure with liquid.
      "BasePath": "{{ ShellSettings.Name }}/Media",
      "CreateContainer": true
    }
  }
}

Note

Only the default Liquid filters and tags are available during parsing of the Liquid template. Extra filters like slugify will not be available.

Media Cache

The Media Cache feature will automatically be enabled when Azure Media Storage is enabled.

The Media Cache feature will cache files stored from Azure Blob Storage, to support image resizing.

The Media Cache feature allows Purging of the Media Cache files stored locally.

You might choose to use the Purging feature if you are fronting the media assets with a CDN. After allowing a long enough period of time for the CDN to have fetched a significant amount of Media assets, both resized, and full size, from the Media Cache you might consider purging the cache.

However please bear in mind that your CDN provider will likely have multiple Points of Presence worldwide, and each of these will maintain their own cache, so while a local CDN PoP might have the asset another PoP may not, until it is requested. At this stage the Media Cache will, if necessary, refetch the asset from Azure Blog Storage, on the fly, and provide it to the CDN PoP.

CDN providers also clear their caches at pre-determined times of their own devising, so while CDN’s are a valuable caching and performance asset, it is important that they are always be able to re-fetch the source file, as and when required, which the Media Cache Module will automatically handle.

Note

The Media Feature is designed to support one storage provider at a time, whether that is local File Storage (the default), Azure Blob Storage, or Amazon S3 Storage.