Umbraco-CMS icon indicating copy to clipboard operation
Umbraco-CMS copied to clipboard

Issue 17128 - Fix GetMediaByPath when querying for media which has been uploaded with dimensions in the file name

Open justin-nevitech opened this issue 4 months ago • 1 comments

Prerequisites

  • [X] I have added steps to test this contribution in the description below

If there's an existing issue for this PR then this fixes:

Fixes #17128

Description

This PR fixes the issue raised in #17128 where media is uploaded to the media library with dimensions in the file name but then cannot be queried using IMediaService.GetMediaByPath (see issue details for more information).

All tests have run and pass.

Steps to Test

  1. Upload a file to the media library which has the name in the format [name]_[width]x[height].[ext], i.e. test_200x200.jpg.
  2. Add the following code into a template to test that the GetMediaByPath finds the media item:
    @inject IMediaService MediaService;

    var media = MediaService.GetMediaByPath("add path to media file here which includes the dimensions");

    if (media != null)
    {
        <p>Media Found! @media.Id</p>
    }
    else
    {
        <p>Media not found!</p>
    }
  1. Repeat the same test with an image that does not contain the dimensions in the file name to ensure this gets returned by GetMediaByPath.

Notes

To be honest, I can't find what may have originally created media files with dimensions in the name, it looks like something must have done this in the past when uploading (so resized images are supported). I can't see where this is done or if it's legacy code so I couldn't see how to test this aspect.

I've completed this PR on v13 but it will need merging into v14 and v15 as well.

justin-nevitech avatar Oct 18 '24 13:10 justin-nevitech