Trying to display a set of images from uComponents' MNTP, and can't get a value for the umbracoFile property - in the example below, both umbracoFile and url return empty strings:
foreach (var id in @Model.sliders) { var media = Model.MediaById(id.InnerText); if (media != null){ var url = media.umbracoFile; <p>name = @media.Name</p> <p>alt = @media.altText</p> <p>url = @media.umbracoFile</p> <p>url = @url</p> } }
It's getting really really really annoying... I've worked around it in other areas like so, using Model.Media:
id.InnerText holds the media id, as expected. From there though, I can't access any of the DynamicMedia properties (umbracoFile, umbracoWidth etc), only media.Name and media.altText. Tried casting as DynamicMedia, for the same result...
I have, but I took a different approach as my requirements changed - I wrote a simple method to grab the image from Examine, based on a few different parameters. I'm sure the same could be achieved using DAMP or similar, but this was as much a learning experience as anything.
My method accepts the following parameters, and returns the img tag as a string:
/// <param name="img">property name representing the image</param> /// <param name="Model">the current page</param> /// <param name="simple">if true, returns the image with no links</param> /// <param name="id">an optional id for the media item, if known - takes precedence over img, if provided</param> /// <param name="width">an optional width for the image, allows resizing on the fly</param>
I've added properties to the image media type, to allow alt text, a default content link and a default document link - the 'simple' param controls what is returned: if there is a link assigned to the image, the img tag is wrapped in the appropriate link tag. If it is a document link, I append the file name, size and type to the returned string. It works for what I needed, and like I said, was more an experiment than anything.
Also having serious issues with umbracoFile property reliability. Seems related to recent upgrade to Umbraco 6.0:
When I run the code below for any older media item (pre-6.0 upgrade), it returns nodeName and umbracoFile correctly. Even items added via DAMP (which we use for some of our media content).
But when I add new Media (by dragging or using Desktop Media Uploader), then put the newly-added node number in the script below, it returns a blank umbracoFile, though nodeName is correctly displayed. The media item itself appears fine (has a URL when you view it in the UI).
The only other change is we started using DAMP a little bit for uploading some media, but it's working fine (I can use the same script below to get umbracoFile for DAMP-uploaded items).
(Related issue: after 6.0 upgrade, any page I have that has a media picker data type on it, I no longer see what media item is picked, even though there is definitely media picked because the page displays correctly on the website.)
So by example, the code below works fine for Media Node 9780 (an older media item), but fails for any new Media Node I've added since 6.0 upgrade (15610 for example). Does display nodeName correctly, but umbracoFile is empty.
MediaById misbehaving...
Trying to display a set of images from uComponents' MNTP, and can't get a value for the umbracoFile property - in the example below, both umbracoFile and url return empty strings:
It's getting really really really annoying... I've worked around it in other areas like so, using Model.Media:
But that will only help if with the media picker data type, not mntp. It shouldnt' be that difficult, should it?
I can get the images to load if I rebuild the internal search index, but they're gone again on subsequent refreshes.
I've seen others having similar problems, and would really appreciate a solution...
ta
Nathan
If you debug what does id.InnerText says? Do you store your data as CSV or XML in MNTP? You could also try DAMP for selecting media.
Jeroen
id.InnerText holds the media id, as expected. From there though, I can't access any of the DynamicMedia properties (umbracoFile, umbracoWidth etc), only media.Name and media.altText. Tried casting as DynamicMedia, for the same result...
Interestingly, if I rebuild the internal search index, then refresh the offending page, the images display. Refresh again, they are gone...
And... code below gets the umbracoFile property:
Ie for a given media folder, I can get the umbracoFile property of it's children. Which doesn't help!
Notice now all images across the site - MNTP or MediaPicker types - are not displaying. Same issue everywhere - umbracoFile is null
It's starting to get really really annoying. Like foot through the computer type annoying.
Nathan , have you resolve it ?
I have, but I took a different approach as my requirements changed - I wrote a simple method to grab the image from Examine, based on a few different parameters. I'm sure the same could be achieved using DAMP or similar, but this was as much a learning experience as anything.
My method accepts the following parameters, and returns the img tag as a string:
/// <param name="img">property name representing the image</param>
/// <param name="Model">the current page</param>
/// <param name="simple">if true, returns the image with no links</param>
/// <param name="id">an optional id for the media item, if known - takes precedence over img, if provided</param>
/// <param name="width">an optional width for the image, allows resizing on the fly</param>
I've added properties to the image media type, to allow alt text, a default content link and a default document link - the 'simple' param controls what is returned: if there is a link assigned to the image, the img tag is wrapped in the appropriate link tag. If it is a document link, I append the file name, size and type to the returned string. It works for what I needed, and like I said, was more an experiment than anything.
N
Also having serious issues with umbracoFile property reliability. Seems related to recent upgrade to Umbraco 6.0:
When I run the code below for any older media item (pre-6.0 upgrade), it returns nodeName and umbracoFile correctly. Even items added via DAMP (which we use for some of our media content).
But when I add new Media (by dragging or using Desktop Media Uploader), then put the newly-added node number in the script below, it returns a blank umbracoFile, though nodeName is correctly displayed. The media item itself appears fine (has a URL when you view it in the UI).
The only other change is we started using DAMP a little bit for uploading some media, but it's working fine (I can use the same script below to get umbracoFile for DAMP-uploaded items).
(Related issue: after 6.0 upgrade, any page I have that has a media picker data type on it, I no longer see what media item is picked, even though there is definitely media picked because the page displays correctly on the website.)
So by example, the code below works fine for Media Node 9780 (an older media item), but fails for any new Media Node I've added since 6.0 upgrade (15610 for example). Does display nodeName correctly, but umbracoFile is empty.
is working on a reply...