Make some asset types download automatically in Optimizely CMS 12 using the Digizuite integration

blog header image

OpenAI DALLE and Allan Thraen

Here is just a quick tip for how you can do custom blob http handling when using the Digizuite integration to Optimizely (Episerver) CMS 12.

This is a quick code sample I put together for a recent client request - I figured it might be useful to others using the Digizuite integration for Optimizely CMS so I am sharing it here.

In this case there was a need to make sure that certain types of assets (files) in Digizuite were always downloaded as attachments when the user would click on a link to them in Optimizely CMS.

Naturally, Digizuite supports the standard Optimizely approach of sending assets out as attachments when the url to them is appended with "/download" but in this case it was needed to be the default behavior for any links to them.

In my local sample site and test DAM I had some PDF files so in this case I configured it for PDF files - but in reality it could be any asset type in Digizuite this would work for.

As you can see in the code sample below, I essentially just piggy-back on the existing infrastructure in the Digizuite integration.

First step is straight forward: Define a custom content type in Optimizely CMS for these asset-types, so we can handle them separately from the rest.

In the case of Pdf files, they are by default handled as a DigizuiteFile (the generic catch all content type included in the integration) so I just inherited from that and made a new type called "DownloadableDocument".

This step is fairly well documented here: https://digizuite.atlassian.net/wiki/spaces/DD/pages/3354657560/DFO+3.1.0+-+2+Modelling+Asset+Content+Types

Next, I inherit the DigizuiteBlobHttpHandler with the single purpose of re-using it's downloading functionality - but just making sure it's used every time.

And finally I created a new Template handler in the shape of a DownloadableFileMediaEndpoint that ties the new content type together with the new custom BlobHttpHandler.

Recent posts