Copied to clipboard

Flag this post as spam?

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

  • Francis 18 posts 98 karma points
    5 days ago

    V12.3.6 How to Obtain Media nodes from IPublishedMediaCache Using Context URL


    I wonder if you can help me out.

    I'm trying to implement a middleware that would intercept url requests from media files and find the media node for it for some processing.


    If I enter https://localhost/mediafolder/4ghyxy/samplefile.pdf from the address bar, the middleware should intercept it and find the media node it's associated to and obtain it's properties for further processing

    This can easily be done in IMediaService by doing:

    var media = mediaService.GetMediaByPath(context.Request.Path);

    However, since this middleware would have multiple requests (I imagine) I wonder if I should be using the Media cache (IPublishedMediaCache) instead for this.

    My problem with that is I can't find any method of obtaining the node that is as efficient as the one above.

    enter image description here

    I would have to traverse through the media tree to obtain to find the file. Like so:

    enter image description here

    Question 1: Is there a more efficient way of doing in the IPublishedMediaCache?

    Question 2: Or is it ok to simply use the IMediaService in this middleware?

    Thanks in advance

Please Sign in or register to post replies

Write your reply to: