Sitecore Media in Database Vs. File Directory Vs. Blob Storage

We understand that Sitecore provides an option to store media library assets either in DB (defaults to DB) or in the filesystem or we can store it in the Azure Blob Storage.

But the question is what is the best option from all three options and why? Here in this blog, I will discuss the pros and cons of all three options and help you to find the best possible option.

1. Sitecore Database: By default, Sitecore provides this option while uploading the media items to the Sitecore Media Library.

If you will delete the Media item from the library, it will be deleted from the Sitecore database and Sitecore also provides a database clean-up tool Cleanup database.

2. File Storage: To upload the media library assets (Image, Video, Pdf, etc) to the file storage you need to update the value of the following variable in the Sitecore. config file:

<setting name="Media.UploadAsFiles" value="false" />

Set it to true.

<setting name="Media.FileFolder" value="/App_Data/MediaFiles" />

Set the value of the path according to your requirement.

Now upload the media items in Sitecore Media Library CMS and your media item will be at the above path instead of a database.

But in this case, if we delete the media items from the Media Library, Sitecore does not delete the asset if we delete it from the Sitecore media library (the physical file will still exist in storage). 

Hence OOTB in Sitecore the physical media files will not be deleted from the storage and will continue to exist.

Sitecore suggested some workaround and provided an article that mentions a few different solutions you can implement to overcome this: Filesystem media is not deleted when deleting Media Library items

Sitecore supports storing the media items in both database and filesystem out of the box. However, the upload to file system functionality has been deprecated so you should consider using storing the media items in the database instead.

3. Azure Blob Storage: All media items are stored in the database and not the file system by default in Sitecore. Alternatively, you could also use the Azure Blob Storage module to store media in Azure Blob Storage instead of the database: Enable the Azure Blob Storage module for Sitecore blobs

Now the questions are:

  1. If we delete media library assets, do they also get deleted from Azure Blob?

    No, they are not deleted, not even orphan blobs. However, orphan blobs can be deleted from Sitecore XP:

    (Control Panel => Administration tools => Database Cleanup => Database Name => Cleanup Blobs => Execute Cleanup)

  2. In the future, if I do not want to continue with the Blob Storage then can I migrate the Media Items to the Database?

    Yes, you use the blob migration tool to help migrate blobs from SQL Database to Azure Storage and vice-versa. Use the blob migration tool

  3. Can Azure Blob utilize the CDN that is provided by Managed Cloud Service to serve its assets?

    Yes, CDN is supported. Compatibility is defined on the general Sitecore XP level, not on the level of a media source.

    Manually configure the Sitecore Media Library to use a CDN

    Because of the "Media.AlwaysIncludeServerUrl" and "Media.MediaLinkServerUrl" settings, media resources will point to CDN.

    Because of the "Media.AlwaysAppendRevision" setting, updated media will have an updated URL, thus URL-based caching mechanism of a CDN should work fine.

Hope now you will have the clarity to choose the best options according to your business requirement.

azure-cdn-sitecore

Happy Sitecoreing ðŸ˜Š

Comments

Popular posts from this blog

Sitecore Installation Error: Failed to Start Service 'Sitecore Marketing Automation Engine'

Import CSV Data in Sitecore Using PowerShell: Part-3

Sitecore Technology MVP Journey 2022