0
votes

We are in the process of migrating media items (images, PDFs, etc) from an old system into Sitecore. Some of the directories in the old system have multiple media items with the same name but different extensions. So if I had to get them via URL they would be as follows -

  • http://example.com/images/test.gif
  • http://example.com/images/test.jpg

They can obviously be reached in the old file based system because their file extensions differ. In Sitecore, out of the box, this is not the case. Multiple items that live under the same node with the same name cannot be reached by adding extensions in front of them. Only the first media item would be hit regardless of the extensions.

Is there a way to get around this? Can Sitecore differentiate between different media items with the same name but different extensions under the same node so that the above 2 URLs would work and point to the respective images?

Thanks

2
Yes. Thank you very much.Gabbar

2 Answers

4
votes

You can override the media provider or the item resolver in the web.config.

follow below steps to check:

Check if that item has another item with same name If so, then check extension. Find the required item that is of that type based on extension and return that.

I think it will help you to find appropriate image.

You can take reference with below URL

http://sitecoreskills.blogspot.co.uk/2014/01/handling-duplicate-media-paths-in.html

3
votes

Or use the built-in setting to make Sitecore use the original filename extensions in the URL. As far as I can remember, this should do the trick for you as well - with 0 lines of code.

  <!--  MEDIA - USE FILE EXTENSION IN ITEM NAMES
        Indicating whether to include a file extension when generating an item name from a file name.
        Default value: "false"
  -->
  <setting name="Media.IncludeExtensionsInItemNames" value="false" />