GetValue<IPublishedContent> Media picker returns null
hi im reading a property from IMember Interface that has a media picker but it is returning a wierd string when i use the non generic method
example string :
umb://media/d18bad45aa50445645564545654
when im using the following generic code, the result returns null ,
i dont know what to do im following the docs?
i think im doing every thing correct ?
im using umbraco 8
I know if this is overkill but the only way i manage to serve the image from an IMember was like this
public string GetMemberImageUrl(IMember contentOwner,string alias ="photo")
{
try
{
var image = contentOwner.GetValue<string>(alias);
if (!string.IsNullOrWhiteSpace(image) && Udi.TryParse(image, out var imageGuidUdi))
{
var imageNodeId = Services.EntityService.GetId(imageGuidUdi);
if (imageNodeId.Success)
{
var mediaItem = _mediaService.GetById(imageNodeId.Result);
return mediaItem.GetUrl("umbracoFile", _logger);
}
}
}
catch
{
}
return RANDOM_USER_IMAGE;
}
Why do you need to use IMember? You can get the member as IPublishedContent.
If you logic in places inside a controller and don't need to set properties on members, you can use MemberShipHelper otherwise MemberService where you are dealing with IMember.
Could you share a bit more of the code and the context?
GetValue<IPublishedContent> Media picker returns null
hi im reading a property from IMember Interface that has a media picker but it is returning a wierd string when i use the non generic method example string : umb://media/d18bad45aa50445645564545654
when im using the following generic code, the result returns null , i dont know what to do im following the docs?
i think im doing every thing correct ? im using umbraco 8
not sure what context you are running your code, but something like this should work
where udiResult = your weird string :) umb://media/d18bad45aa50445645564545654
Hi Wilmar
Is the Media Picker configurated to allow single or multiple images? The default Media Picker datatype instance allow to select multiple items.
You can create a new datatype instance e.g. "Image Picker" and configurate this to not allow selecting multiple items (and maybe not folders?).
Then the following should work:
Otherwise you might try this:
/Bjarne
I know if this is overkill but the only way i manage to serve the image from an IMember was like this
Why do you need to use
IMember
? You can get the member asIPublishedContent
.If you logic in places inside a controller and don't need to set properties on members, you can use
MemberShipHelper
otherwiseMemberService
where you are dealing withIMember
.Could you share a bit more of the code and the context?
Thanks you solve my problem, I'm new to Umbraco so it's difficult to understand their setup
Aa okej i think I understand know IMember is to modify the data and IPublishedContent is more for reading i gonna try that thanks 😊
You are welcome :)
Feel free to ask any questions on the forum.
A great start is also the videos on https://umbraco.tv/
is working on a reply...