Skip to content

Azure Media (OrchardCore.Media.Azure)

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

Azure Media Storage (OrchardCore.Media.Azure.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",
       // Activates an event to create the container if it does not already exist.
      "CreateContainer": true,
      // Whether the 'Container' is deleted if the tenant is removed, false by default.
      "RemoveContainer": 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.

Azure Media ImageSharp Image Cache (OrchardCore.Media.Azure.ImageSharpImageCache)

The feature replaces the default PhysicalFileSystemCache of ImageSharp that stores resized images in the App_Data folder with AzureBlobStorageImageCache that stores them in Azure Blob Storage. Depending on your use case, this can provide the following advantages:

  • Persistent image cache not to have to repeatedly resize images, even if the local file system of the webserver is ephemeral. This helps if you e.g. use containers to host the app, or do clean deployments to the webserver that remove all previously existing files.
  • Better performance if disk IO is a bottleneck: The local storage of the webserver may be slow or access to it deliberately throttled, like it is the case with Azure App Services. Using Blob Storage can alleviate pressure on the local disk, leaving more resources available to serve other requests, as well as offer a higher request per second limit for image requests.

Note

Cache files are only removed for a tenant when removing the tenant itself if you use a separate container for each tenant.

Configuration

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

{
  "OrchardCore": {
    "OrchardCore_Media_Azure_ImageSharp_Cache": {
        // 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",
        // Activates an event to create the container if it does not already exist.
        "CreateContainer": true,
        // Whether the 'Container' is deleted if the tenant is removed, false by default.
        "RemoveContainer": true
    }
  }
}

Note

Templating the configuration and configuring a container per tenant work the same way as for Azure Media Storage; follow its documentation above.