Sitecore - 2 Media items. Same filename, different extensions

1.2k views Asked by At

If you have 2 media items that have the same name but different extensions, Sitecore cannot differentiate between them.

For example:

  • /~/media/myfile.pdf

  • /~/media/myfile.doc

When these URL's are requested, the PDF file is returned in both cases.

I understand that that Sitecore ignores the extension in the request, and that the real problem is in fact, that I essentially have two items with the same path in the media library:

sitecore/media library/myfile

However, I do think it's a reasonable that our customer would want to store both PDF and DOC versions of the same document in a single node.

I found this article which addresses the related problem of ensuring that the requested media item file extension is valid:

http://www.cognifide.com/blogs/sitecore/sitecore-serves-media-items-even-with-incorrect-extensions/

However, this is still based on the premise that you have obtained the correct Sitecore item in the first place (which isn't true in the case of the request for myfile.doc).

So I guess my question is whether there is a way prevent Sitecore from simply getting the first item it finds and to take the extension into account.

1

There are 1 answers

4
Mark Ursino On BEST ANSWER

You can possibly override either the media provider or the item resolver in the web.config and if the requested resource is a media item:

  1. See if it has a sibling by the same name
  2. If so, check the request's extension (doc, PDF, etc)
  3. Find the sibling that is of that type based on extension and return that.