问题
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:
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:
- See if it has a sibling by the same name
- If so, check the request's extension (doc, PDF, etc)
- Find the sibling that is of that type based on extension and return that.
来源:https://stackoverflow.com/questions/21056941/sitecore-2-media-items-same-filename-different-extensions