Uploading an image via Image field returns broken in SC version 8.1 Initial release and 8.1 Update-1 [short-term & long-term fix]
Last week, I was tapped to troubleshoot a production issue related to image upload via Image field (logo field) of a header item.
The client reported that when they upload an image that has ‘-‘ and spaces around it (eg. main – logo.jpeg), it throws a broken image when viewed in the image upload dialog box.
Figure 1 : Browse a media file
Figure 2 : Uploaded
Figure 3 : Looking at the browser console log, it returned a 404 (not found) error.
Figure 4 : Opening the link returns ‘A request document was not found’
I really wanted to help, so I made an investigation across all Sitecore platform versions (8.X) to simply check if this was an existing bug and if has a fix already. I also considered checking the latest version of Sitecore (as of this writing, v.8.1-U2) before jumping to a conclusion that it is probably because of a wrong configuration file / DLL or a customization.
I jotted down the result of each of the platform versions, to easily compare where and what version of Sitecore it could be encountered. I used a freshly installed instances for the purpose of my testing.
Platform version, image upload testing result:
- 8.0 Update-3 : Working via Media Library & image upload
- 8.0 Update-4 : Working via Media Library & image upload
- 8.1 Initial release : (current version of the client): NOT working via image upload, but working via Media Library.
- 8.1 Update-1 : NOT working via image upload, but working via Media Library.
- 8.1 Update-2 : Working via Media Library & image upload
In a high level explanation:
Say, we have this image file (eg. main – logo.png), when a content user uploads it to Sitecore, the mechanism behind the parsing of this file will be treated like this : main–––logo.jpeg. And therefore, the error 404 not found was encountered in the browser console log which turns to a broken image upon viewing in the image upload dialog box. Surprisingly, when a client user uploaded an image via Sitecore > Media Library, the image displayed properly. Strange, isn’t it?
In a detailed explanation:
- When you upload an image (eg. main – logo.jpeg) via image upload in Sitecore v.8.0 Update-3 and v.8.0 Update-4, it was uploaded properly without any issue.
- You may view the image by navigating to this sample URL: http://8.0-u3/sitecore/shell/~/media/main%20–%20logo.ashx?bc=Transparent&db=master&h=130&thn=1&w=130
- When you upload an image (eg. main – logo.jpeg) in v.8.1 Initial release (In my case, this is the current version of the client instance) and in v.8.1 Update-1, Sitecore introduces a new – line 1844 in the figure below
Node under the:
That causes the problem. After removing the node <replace>, and test again, the image upload works as expected.
- You may view the image with ERROR by navigating to this sample URL: http://8.1-initial/sitecore/shell/-/media/main–––logo.ashx?bc=Transparent&db=master&h=130&thn=1&w=130
- You may also view the image WITHOUT ERROR by navigating to this sample URL: http://8.1-initial/sitecore/shell/-/media/main%20–%20logo.ashx?bc=Transparent&db=master&h=130&thn=1&w=130
- When you upload an image (eg. main – logo.jpeg) via image upload in Sitecore v.8.1 Update-2, you will experience the same working behavior just like the #1 (in v.8.0 Update-3 and v.8.0 Update-4).
- Looking at the web.config file, the dash ‘-‘ replace node is still exists.
- And it is still working.
By this time, I suspected that it has something to do with the binaries. So what I did, is to play around with Sitecore.Kernel by replacing the Sitecore.Kernel version of v.8.1 Initial release to v.8. Update 2. I tested it again and it works!
By replacing the Sitecore.Kernel.dll, it fixed the issue without altering any configuration on the freshly installed instances.
I raised my findings to our solution architect by providing a short-term and a long-term fix.
Since my personal take is to provide an immediate remedy, considering that the client content users are consistently uploading image and should not be interrupted. So my short-term proposal is to inform the client that every time they upload an image:
- They can use the Media library and referenced the image (eg. main – logo.jpeg) to ITEM ABC (eg. header item)
- They can use image upload dialog box > upload media file BUT with caution. During the upload, the client content users are forced to change the name of the image if has dash(es) and remove the spaces before and after those dash(es).
- Explore upgrading the Client instance to v.8.1 Update-2
- Raise to Sitecore, so they can provide a patch on this. (In progress)
- I doubled check the known issues page in v.8.1 Initial release up to v.8.1 Update-2, but it seems that this was not yet reported
- Dissect the Sitecore.Kernel and provide a custom patch, by checking the assembly and override the mechanism relative to the encodeNameReplacement specific
- Connect with the client
- Test client production instance
- Test in all platform versions (freshly installed)
- via Media Library
- via Image upload dialog box
- Check release notes and know issues of 8.X
- Override the Sitecore.Kernel.dll with the latest version (v.8.1 Update-2)
- Provide a proposals
- Short-term fix
- Long-term fix
Happy Sitecoring day, everyone!
- Sample logo image: http://www.logomyway.com/