I am loading a member, which is, of course, returned as an IMember but when I try to access its photo through GetValue< MediaWithCrops >("photo") I am getting a null.
If I try using GetValue("photo"), I get the following:
It looks like the problem is that you can't cast that property to "MediaWithCrops" model.
What I usually do in these cases is to do var photo = GetValue("photo") with out the template cast and that way check which model the photo variable is by debugging. Is that exactly what you did there?
I think I used IPublishedContent for images, MediaWithCrops is new to me.
I think I solved it.
You need to use a different service called MemberManager.
var authorTemp = await _memberManager.FindByNameAsync(authorName);
var author = _memberManager.AsPublishedMember(authorTemp);
var avatarImage = author.Value<MediaWithCrops>("photo");
You can inject it with the interface IMemberManage from Umbraco.Cms.Core.Security.
IMember.GetValue<MediaWithCrops>("photo") returning null
Hey everyone.
I am loading a member, which is, of course, returned as an IMember but when I try to access its photo through GetValue< MediaWithCrops >("photo") I am getting a null.
If I try using GetValue("photo"), I get the following:
I'm using MediaPicker3 and Umbraco 9.1.1.
Any light shed into this would be much appreciated.
Thank you very much!
Hi Sérgio
It looks like the problem is that you can't cast that property to "MediaWithCrops" model.
What I usually do in these cases is to do var photo = GetValue("photo") with out the template cast and that way check which model the photo variable is by debugging. Is that exactly what you did there?
I think I used IPublishedContent for images, MediaWithCrops is new to me.
Hope this will help.
Best regards Frank
Hi Frank. Thank you very much for pitching in.
MediaWithCrops is the new type that MediaPicker3 uses. When I try GetValue("Photo") I get that JSON I have shown before, so it's not even an Udi.
That's wierd. In the docs it says media picker 3 return IPublishedContent or IEnumerable
https://our.umbraco.com/documentation/fundamentals/Backoffice/Property-Editors/Built-in-Property-Editors/Media-Picker/
Best regards Frank
That's the old Media Picker.
Media Picker 3 (the new one, which I am using), returns MediaWithCrops. Check it out here.
Sorry I see.
Have you tried IEnumerable
Best Regards Frank
I have, although it should only return a single object. I have tried that, IPublishedContent as well (and IEnumerable of IPublishedContent).
None of it worked :(
Bumping this to see if we can get more eyes on it. I find it weird that no one else has found this issue or has a possible answer for it.
Can you post your code ? Then I will have a look.
Hi Frank. Sure. Thanks.
avatarImage is always null. I have also tried it with IPublishedContent, IMedia, just .GetValue("photo"). Nothing works.
.GetValue("photo") returns the following, as I indicated above:
I think I solved it. You need to use a different service called MemberManager.
You can inject it with the interface IMemberManage from Umbraco.Cms.Core.Security.
Hope that helps :)
Best Regards Frank
Thanks, Frank. That's it. Appreciate your time!
is working on a reply...