Copied to clipboard

Flag this post as spam?

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


  • David 20 posts 131 karma points
    Nov 22, 2019 @ 17:35
    David
    1

    Can I check what media is about to be rendered using a Media Picker?

    Is there a way I can find out what sort of file is in the Media Picker and render it out accordingly.

    For images I would use

    @if (Model.Hero != null) {
        <img src="@Model.Hero.Url">
    } else (video) {
        <video class="c-home-video-inner" src="@Model.Hero.Url" poster loop autoplay preload="auto" muted playsinline></video>
     }
    

    Say a video (.mp4) was uploaded, however, I would need to format it for a video.

    Can I do a check based on the extension, perhaps?

    If it's an image do this, for a video, this?

    Thanks in advance

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Nov 22, 2019 @ 19:42
    Marc Goodson
    102

    Hi David

    Every Media item uploaded has a special property with alias called 'umbracoExtension'

    So you should be able to read that from your hero property (if that is a picked media item), I usually do a similar thing to display an appropriate icon next to the file... but you could just change the markup depending on the type:

    eg

    var fileExtension = Model.Hero.Value<string>("umbracoExtension");
     string iconClass = "fa-file-download";
                switch (fileExtension) {
                    case "pdf":
                        iconClass = "fa-file-pdf";
                        break;
                    case "ppt":
                    case "pptx":
                        iconClass = "fa-file-powerpoint";
                        break;
                    case "xls":
                    case "xlsx":
                        iconClass = "fa-file-excel";
                        break;
                    case "doc":
                    case "docx":
                        iconClass = "fa-file-word";
                        break;
                    case "mp4":
                        iconClass = "fa-file-video";
                        break;
                    case "jpg":
                    case "jpeg":
                    case "png":
                    case "gif":
                        iconClass = "fa-file-image";
                        break;
                }
    

    if that helps give you a steer?

    regards

    Marc

  • David 20 posts 131 karma points
    Nov 23, 2019 @ 13:01
    David
    0

    Can't thank you enough Marc :-)

Please Sign in or register to post replies

Write your reply to:

Draft