I have the below 2 lines of code. Through debugging, I can examine media and I see it having an id, however when the 2nd line is run, mediaItem returns null.
var media = Model.GetPropertyValue("Testimage");
var mediaItem = Umbraco.TypedMedia(media);
Figured it out. Was because when you upgrade a site Umbraco creates (Obsolete) media picker because it now need to use UID. So when changing the datatype to the MediaPicker2 then your code works :)
There is a configuration option in umbracoSettings.config that allows you to revert it to behave how it used to but I wouldn't recommend it as this is how things will be forever more (it's really for upgrades that won't work easily)
umbraco 7.6 API model issue with typedmedia
I have the below 2 lines of code. Through debugging, I can examine media and I see it having an id, however when the 2nd line is run, mediaItem returns null.
var media = Model.GetPropertyValue("Testimage"); var mediaItem = Umbraco.TypedMedia(media);
Hi Reinjunon
So one time this code works, another doesn't?
What is the problem?
Did you change something with this media item in database?
Thanks,
Alex
Hi,
Try this:
This is due to media pickers now returning IPublishedContent in v7.6.
This would actually allow you to simplify to a single line:
Jeavon
And if this code just returns null then what is wrong? :)
Upgraded 7.5.11 to 7.6 and merged configs correctly. Is using a media picker. Have republished all content. Works with the old code, but not the new.
Figured it out. Was because when you upgrade a site Umbraco creates (Obsolete) media picker because it now need to use UID. So when changing the datatype to the MediaPicker2 then your code works :)
Converters work with with both MediaPicker and MediaPicker2
What returns with:
The id of the image. 1116 in this case
How do you know this Jeavon? I was trying to use var mediaItem = Umbraco.TypedMedia(media.Id) to no avail...lol
:) It's one of the features of v7.6 and I worked on it
Documentation needs to be migrated from https://github.com/Jeavon/Umbraco-Core-Property-Value-Converters (you can use that for now, this is the default in Umbraco v7.6 now) which is one of the tasks I'm hoping to work on soon.
There is a configuration option in umbracoSettings.config that allows you to revert it to behave how it used to but I wouldn't recommend it as this is how things will be forever more (it's really for upgrades that won't work easily)
Jeavon
is working on a reply...