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.
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;
}`
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:
That seems to be the way Matt did it. Even if I just try to print out
imageId
, it is empty.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>
orGetVortoValue<IPublishedContent>
?If I do:
I get this error:
Same happens with IPublishedContent.
Any idea?
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
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;
Hope this helps! Revert in case of queries!
BR, Ranjit J. Vaity
is working on a reply...