Skip to content

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

Merged
Zeegaan merged 1 commit intoumbraco:v13/devfrom
justin-nevitech:issue-17128-v13
Oct 21, 2024
Merged

Issue 17128 - Fix GetMediaByPath when querying for media which has been uploaded with dimensions in the file name#17314
Zeegaan merged 1 commit intoumbraco:v13/devfrom
justin-nevitech:issue-17128-v13

Conversation

@justin-nevitech
Copy link
Contributor

Prerequisites

  • 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.

… path for files that contain the sizes in the file name (i.e. image_200x200.jpg)
@github-actions
Copy link

github-actions bot commented Oct 18, 2024

Hi there @justin-nevitech, thank you for this contribution! 👍

While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@emmagarland
Copy link
Collaborator

@justin-nevitech thanks for your PR to fix the issue #17128!

One of the Core Collabs team will review it soon 🙌

@Zeegaan Zeegaan self-requested a review October 21, 2024 06:46
@Zeegaan
Copy link
Member

Zeegaan commented Oct 21, 2024

Looks good, tests good, and covers the old use case too🚀
Thanks for opening up the fix for the 13 dev branch 🙏

@justin-nevitech
Copy link
Contributor Author

Thanks @Zeegaan Sorry for the branching issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants