Copied to clipboard

Flag this post as spam?

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


  • Morten 105 posts 345 karma points
    Mar 09, 2017 @ 09:00
    Morten
    0

    Media Picker and Vorto - How do I get the image?

    I'm trying to grab the image from my content page. I have a master page, which has a bunch of Vorto fields for translation, including a Vorto Media Picker, where I uploaded my files.

    How on earth do I get the URL of the image? I've tried this, which Matt did in a uHangout call:

    @ {
        var imageId = Model.Content.GetVortoValue("culture");
    }
    
    <img src="@Umbraco.TypedMedia(imageId).Url" />
    

    That seems to be the way Matt did it. Even if I just try to print out imageId, it is empty.

  • Stefano 61 posts 313 karma points c-trib
    Mar 09, 2017 @ 09:24
    Stefano
    0

    Just had a look at my code and it's done casting to an IPublishedContent but it supposed it should work as you are doing it!

    Maybe try GetVortoValue<int> or GetVortoValue<IPublishedContent> ?

  • Morten 105 posts 345 karma points
    Mar 09, 2017 @ 09:27
    Morten
    0

    If I do:

    var imageId = Model.Content.GetVortoValue<int>("culture");
    

    I get this error:

    Cannot assign method group to an implicitly-typed variable

    Same happens with IPublishedContent.

    Any idea?

  • Ranjit J. Vaity 66 posts 109 karma points
    Jul 23, 2017 @ 16:13
    Ranjit J. Vaity
    0

    Hi Morten,

    Bit late to reply but I happen to figure out to pull out media from Cms. There are many posts that revels these but are scattered.

    The methods below, I had Languages (countryCode as text and countryFlag as mediaPicker) in Archetype and then I try to pull the data from these properties. This archetype is created on SiteSettings page.

    Method to get Languages from Archetype that is created on siteSettings page

    ` public IEnumerable

            foreach (var fieldset in flagList)
            {
                LanguageFlagViewModel flag = new LanguageFlagViewModel();
    
                foreach (var item in fieldset.Properties)
                {
                    if (item.Alias == "countryCode")
                    {
                        flag.CountryCode = Convert.ToString(item.Value).Trim().ToLower();
                        foreach (var lang in siteLanguages)
                        {
                            if (lang.CultureInfo.TwoLetterISOLanguageName == flag.CountryCode)
                            {
                                var currentUrl = currentPage.Url.TrimStart("/" + @currentCulture);
                                flag.LanguageUrl = "/" + lang.CultureInfo.TwoLetterISOLanguageName + currentUrl;
                            }
                        }
                    }
    
                    if (item.Alias == "countryFlag")
                    {
                        flag.FlagImageUrl = _cmsMediaService.GetImageUrl(GuidUdi.Parse(Convert.ToString(item.Value)));
                    }
    
    
                }
                flags.Add(flag);
            }
            return flags;
        }`
    

    In the recent versions of Umbraco, I think after 7.6.1, we get Udi / GuidUdi from Media picker instead of just id, using which we can get further the media from cms. see the below function.

    `

    public string GetImageUrl(GuidUdi mediaUdi) { string imageUrl = string.Empty;

            Attempt<int> data = _entityService.GetIdForKey(mediaUdi.Guid,
                (UmbracoObjectTypes)Enum.Parse(typeof(UmbracoObjectTypes), mediaUdi.EntityType, true));
            if (data.Success)
            {
                imageUrl = _umbracoHelper.TypedMedia(data.Result).Url;
    
            }
            return imageUrl;
        }`
    

    Hope this helps! Revert in case of queries!

    BR, Ranjit J. Vaity

Please Sign in or register to post replies

Write your reply to:

Draft