Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark Bowser 273 posts 860 karma points c-trib
    Apr 29, 2015 @ 22:36
    Mark Bowser
    0

    Alternate ways to get media nodes by path of media file

    My goal is to use the umb v6/7 api to get IMedia from the database by the path of the media file that is saved.

    For example, given only "/media/1008/403986101520723026704221344448958_n.jpg", how can I use the Services.MediaService to find the media item?

    I saw that there is a Services.MediaService.GetMediaByPath(mediaRelPath) that I can call. Unfortunately, as far as I can tell, there is a bug through the current v7.2.4 where GetMediaByPath only works if the media is stored in "umbracoFile" and only if the media path is what is stored by the property editor. We are using ImageCropper as our media property editor and have changed the "umbracoFile" property into that ImageCropper. This means that our media is stored as JSON and GetMediaByPath can't find the media item by path.

    Does anyone else have any elegant ways to get the media by path. I need to come up with something because even if GetMediaByPath is fixed shortly, I need the code I am working on to be reverse compatible with older v6/7 versions of umbraco.

    I'll settle for solutions that don't hit the DB if I need to. My next step is to look at leveraging examine for this info.

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft