Sitecore 7.2 Upgrade Media Library Gotcha
EncodeNameReplacements Now Applies To Media Items
If you have spaces in your Media Library item names, this will be important to you.
While upgrading a client to Sitecore 7.2 this section of the release notes gave us pause:
Media API When rendering media URLs, the system did not use the configuration in the encodeNameReplacements section to replace special characters in the URLs. This has been fixed so that media URLs also use the encodeNameReplacements configuration. (323105, 314977)
Summary: media library URLs now use the encodeNameReplacements configuration.
This will affect your Sitecore install if:
- You are using encodeNameReplacements to replace whitespace in item names with hyphens in item URLs
- And you have Media Library item names containing hyphens
This definitely applies to a few our instances. Mostly because the Media Library takes the original assets filename as the items name. Filenames are often formatted with hyphens.
Use Sitecore Powershell or something similar to execute code, removing all hyphens from Media Library names. For us this approach had the following drawbacks:
- Media Library is very large
- Media Library is not included in our standard production release
- We don't run data migration code against production environments
- Fragments atomicity of the upgrade
- Regression testing to validate content authored links to Media Library content
Replace Sitecore's MediaProvider with our own, removing the newly added encodeNamesReplacement functionality for Media Library items.
We're going with Option 2. It's the best option for us when accounting for timelines, stability and the drawbacks of our specific situation outlined in Option 1 listed above.
We're doing Option 2 which means we're using our own MediaProvider and removing the encodeNamesReplacement functionality.
We have 3 files that we'll compile into one assembly:
|FishtankMediaRequest.cs||Removes decoding of media library assets, inherits MediaRequest|
|FishtankMediaProvider.cs||New Media Provider reference in web.config, inherits MediaProvider|
|FishtankMediaConfig.cs||Allows use of FishtankMediaRequest for decoding requests, inheritsMediaConfig|
To use this, we'll find the mediaProvider section in the web.config and swap out the class and assembly. It's located at configuration > sitecore > mediaLibrary > mediaProvider.
<mediaLibrary> <!-- MEDIA PROVIDER The media provider used to generate URLs, create media items, control media caching, parse media requests, and other media related functionality. --> <!-- <mediaProvider type="Sitecore.Resources.Media.MediaProvider, Sitecore.Kernel"/>-- > <mediaProvider type="Fishtank.MediaResolverPatch.FishtankMediaProvider, Fishtank.MediaResolverPatch" />
Now we've successfully reverted Sitecore 7.2 to resolve and render Media Library URLs as it did pre-upgrade. Again, all code is on GitHub.
We will keep Option 1 in our pocket as part of our next major-version Sitecore upgrade.
Thanks for reading. This article was authored using Markdown for Sitecore.