Copied to clipboard

Flag this post as spam?

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


  • Danine Noble 82 posts 369 karma points
    Dec 10, 2021 @ 17:57
    Danine Noble
    0

    Replacing 'Current' for File Service (Rendering SVG Inline)

    Afternoon all ^^ How does one get an SVG to render inline without 'Current' in v9?

    What worked for v8 (as helped here):

    Current = Umbraco.Core.Composing.Current;
    ...
    using (var stream = Current.MediaFileSystem.OpenFile(media.Url()))
    { ... }
    

    What do you replace the old Composing.Current with when using this in a Service since v9 did away with it?

  • Benjamin Carleski 33 posts 294 karma points MVP c-trib
    Dec 10, 2021 @ 19:10
    Benjamin Carleski
    100

    If you are in a view, you can use view injection to get the IMediaFileManager reference, then use that to get to the file, as is shown below.

    @inject Umbraco.Cms.Core.IO.MediaFileManager _mediaFileManager
    ...
    @{
        using (var stream = _mediaFileManager.FileSystem.OpenFile(media.Url()))
        {
        ...
        }
    }
    

    If you are in an extension class, or some other place that doesn't have a direct way to inject a MediaFileManager instance, you'll have to pass it in as a method argument. Then the caller, be it a view or controller, can inject in the MediaFileManager instance and pass it to your method.

  • Danine Noble 82 posts 369 karma points
    Dec 10, 2021 @ 20:55
    Danine Noble
    0

    Yeah, am trying to use it in a Method from a Service since it's a handy thing just all over the site not in any one particular view. I had been experimenting with the mediaFileManager but it always came out null. I thought passing a service into a service was a silly way to go about it but I suppose I was wrong xD Not well versed outside of HTML/CSS land.

    Thanks so much Benjamin!

    <3

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies