Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    May 08, 2012 @ 08:38
    Nathan Woulfe
    0

    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: 

     

                   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:

    <img src="@Model.Media("topRightImage", "umbracoFile")" alt="@Model.Media("topightImage", "altText")" />

    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

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    May 08, 2012 @ 12:41
    Jeroen Breuer
    0

    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

  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    May 09, 2012 @ 01:11
    Nathan Woulfe
    0

    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...

  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    May 09, 2012 @ 04:50
    Nathan Woulfe
    0

    Interestingly, if I rebuild the internal search index, then refresh the offending page, the images display. Refresh again, they are gone...

  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    May 09, 2012 @ 07:29
    Nathan Woulfe
    0

    And... code below gets the umbracoFile property: 

    var folderId = 3478;
    var m = Model.MediaById(folderId);
    var items = m.Children;
    foreach (var item in items) {
    @item.umbracoFile
    }     

    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.

  • Idan 3 posts 23 karma points
    Dec 26, 2012 @ 16:28
    Idan
    0

    Nathan , have you resolve it ?

  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    Jan 08, 2013 @ 00:02
    Nathan Woulfe
    0

    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

     

  • Eric Schrepel 161 posts 226 karma points
    Feb 11, 2013 @ 23:03
    Eric Schrepel
    0

    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.

    @{
    dynamic image = Model.MediaById(15610);
        <p>@image.nodeName @image.umbracoFile</p>   
    }
Please Sign in or register to post replies

Write your reply to:

Draft