Copied to clipboard

Flag this post as spam?

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


  • Rasmus Lynggaard 118 posts 325 karma points
    Apr 15, 2020 @ 14:33
    Rasmus Lynggaard
    0

    How to retrieve media usage?

    In Umbraco 8.6 you can now see where a media item is used directly on the media in the media section - that's is excellent and I love it. How do I retrieve that information via the API/services?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 15, 2020 @ 14:35
    Alex Skrypnyk
    0

    Hi Rasmus

    Do you want to use media in the backoffice or externally?

    Alex

  • Rasmus Lynggaard 118 posts 325 karma points
    Apr 15, 2020 @ 14:39
    Rasmus Lynggaard
    0

    It's I have an eventhandler MediaService.Saved += MediaServiceOnSaved; and for each saved entity I want to know which other items the media is used in

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 15, 2020 @ 14:45
    Alex Skrypnyk
    0

    But event handler isn't API, so you need to track changes in media items?

  • Rasmus Lynggaard 118 posts 325 karma points
    Apr 15, 2020 @ 14:49
    Rasmus Lynggaard
    0

    Yeah. That's why I wrote /Services :-)

    I need to know which other items is using a media item, at the time the media item is saved (or deleted). I need this because I need to handle those items aswell, when the media is updated

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 15, 2020 @ 14:51
    Alex Skrypnyk
    0
  • Rasmus Lynggaard 118 posts 325 karma points
    Apr 15, 2020 @ 14:53
    Rasmus Lynggaard
    0

    The relation must be there already, since it's shown OOTB in 8.6 Guess I'll have to look in the source :-)

  • Joep 96 posts 698 karma points
    Apr 15, 2020 @ 15:17
    Joep
    1

    Hi Rasmus,

    There is a service you can use, its called the 'RelationService' I think.

    -Joep

  • Rasmus Lynggaard 118 posts 325 karma points
    Apr 15, 2020 @ 18:43
    Rasmus Lynggaard
    100

    I've now been looking at how it's done in the core and it's using the RelationService

    Services.RelationService.GetPagedParentEntitiesByChildId(int id, long pageIndex, int pageSize, out long totalChildren, params UmbracoObjectTypes[] entityTypes)
    

    Where entityTypes is fetched with ObjectTypes.GetUmbracoObjectType(entityType); entityType being DOCUMENT, MEDIA or MEMBER

Please Sign in or register to post replies

Write your reply to:

Draft