Tag Archives: Media

No images after upgrading to Sitecore 7.5

With the release of Sitecore 7.2 encode name replacements now applies to media URL’s, prior to 7.2 it only applied to content items, and therefore media URL’s with spaces used to be like the following:

/-media/some%20item%20with%20space/test-xx-yy.jpg

But with Sitecore 7.2, they can be as follows:

/-media/some-item-with-space/test-xx-yy.jpg

This change in fact caused all the images on the site I was upgrading to disappear, but first a quick introduction to Encoding name replacement.

It provides the ability to specify text replacements to use when the media manager generates the friendly URL for a media item. The element /sitecore/encodeNameReplacements in the web.config; contains a number of replace elements and each replace element defines what to find and replace.

<encodeNameReplacements>
      <replace mode="on" find="&amp;" replaceWith=",-a-," />
      <replace mode="on" find="?" replaceWith=",-q-," />
      <replace mode="on" find="/" replaceWith=",-s-," />
      <replace mode="on" find="*" replaceWith=",-w-," />
      <replace mode="on" find="." replaceWith=",-d-," />
      <replace mode="on" find=":" replaceWith=",-c-," />
</encodeNameReplacements>

Strangely enough replacing a space with a dash is not defined by default, but I have added it to almost every solution as %20 in URL’s kills SEO. Below is the element you need to add to achieve that spaces are replaced by dashes.

<replace mode="on" find=" " replaceWith="-" />

Nemesis and side effects

I have reported to Sitecore support a number of times that I thought that encode replacements should apply to media URL’s. So with 7.2 I got my wish and this is where nemesis strikes me as after upgrading to Sitecore 7.2 all the product images disappeared from the site.
The solution has over 50000 images which are synchronized from their PIM (Product Information Management) and name of media item had a space and a dash.
If you want to have spaces replaced with dashes the one restriction is that you can no longer have dashes in the items name. Because when Sitecore tries to resolve the URL it applies the reverse of any encode replacements i.e. sitecore replace all dashes with a space to find the item path.
For example assume that your media item has a space and a dash in its name.

/media library/cars/myCar 26-10-2013

The URL will be

/~media/cars/myCar-26-10-2013.jpg

But when Sitecore tries to resolve the URL to find the image it replaces all the dashes with spaces (i.e. the reverse of the encode name replacement) and then it can’t find the item at the following path.

/media library/cars/myCar 26 10 2013

There are a number of solutions

  • Write script to replace all dashes with a space in the media library
  • Create a custom media provider, which doesn’t execute the encode replacements.

Whist I try to avoid modifying standard sitecore behavior in this case I choose to override the GetMediaUrl of the MediaProvider, as it is not possible to change the image names due to the business requirements of the site.

Anyway I hope this helps anybody if there images disappear after upgrading to 7.5.

Sitecore SPEAK Uploader File types

In a previous post I introduced the Uploader control, since then I noticed it wasn’t possible to attach pdf’s and or any other file type that was not an image.

Each time I uploaded a pdf file, it would put a red boarder around the file, and no item was created in Sitecore.

error

ImageTypes – Setting

After some investigation, I found that the ImageType setting in the web.config defines what image (files) types can be uploaded via the SPEAK uploader control. If you append “pdf” for example it is possible to upload pdf’s.

pdf

 

I don’t like that I have to specify that PDf is an image type, as this might have other unwanted side effects. But when using the SPEAK uploader control, it creates the correct item type (i.e. PDF).

item

Sitecore SPEAK – Dialog Rendering

The standard way to add/create dialog’s in SPEAK is to add the Dialog Window control, and then add the controls required by the dialog to the Dialog Window’s placeholders.
This has a number of disadvantages

  • Each new page that requires the dialog has to add all the renderings/settings that the dialog requires.
  • The code related for the dialog is added to the code page.
  • If you need to add/remove controls from the dialog you have to update all the pages that use the dialog
  • If you have a page with a lot of dialog’s the page will have a LOT of controls and all the code

In order to address the afore mentioned issues and enable reuse of dialog’s across a number of pages, we introduced the concept of a Dialog Rendering item; which contains all the renderings required by the Dialog, and defines its own sub-page code which contains the code required by the dialog.
In this blog we will create a attachment dialog, as the uploader control that comes with SPEAK is very cool (look out for an upcoming blog post)..

attachment dialog

Adding/showing a dialog

There are a 4 steps in order to add and then show a dialog:

  1. Create the Dialog Rendering Template. (Whilst this is not required, as you could add the layouts to any item, I would strongly recommend defining a template).
  2. Create the Dialog Rendering item
    1. Add the Dialog Window Control and add the required controls to the Dialog Window placeholder.
    2. Add a SubPageCode control and create the JavaScript which provides the functionality required by the dialog.rendering item
  3. Add the dialog to the page using Client side insert renderings.
    1. The guid is the rendering item id (i.e. the attachment item defined in step 2).
    2. Then save the dialog in the subpage controls list with a unique name.
contextApp.insertRendering("{26D93861-13E8-4416-8319-0D03094A19CB}", { $el: $("body") }, function (subApp) {
        contextApp["showAddAttachmentDialog"] = subApp;

      });

  1. To show the dialog the show function on the DialogWindow control has to be called. There are a number of ways this could be achieved, but I decided to implement it as follows
    1. In the initialize function for the dialog (SubPageCode JavaScript), set up an event handler to listen for a show event i.e. add:attachment:dialog:show.
    2. Define a showDialog function which calls the DialogWindow.Show().code
    3. To show the dialog, trigger the event and pass the in the required parameters.events & paramter

Context Issue

The dialog does not have access to the page’s context and controls; therefore you pass the required context via the event parameters.
This in fact reduces dependencies as the only dependency is the event parameters; therefore the dialog is not aware of where it is called from.