Copied to clipboard

Flag this post as spam?

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


  • Roger Jarl 22 posts 115 karma points
    Jun 05, 2017 @ 09:46
    Roger Jarl
    0

    String "nnnn" is not a valid udi

    After upgrading from 7.6.2 to 7.6.3 I get this error: String "1705" is not a valid udi. I have EnablePropertyValueConverters set to true in both 7.6.2 and 7.6.3. My Partial View Macro:

    <div class="row">
    <div class="col-sm-12">
    @foreach (var page in startPage.Children.Where("Visible").Where("showPanel")) {
        <div class="panel">
            <a href="@page.Url">
            <div class="panel-heading">@page.Name</div>
            <div class="panel-body">
                @{
                if (page.HasValue("imgPanel")) {
                <div class="panel-body-image">
                    <img src="@Umbraco.Media(page.imgPanel).Url" alt="" />
                </div>
                }
                }
                <div class="panel-body-text">@page.panelText</div>
            </div>
            </a>
        </div>
    }
    </div>
    

    The error comes from "@Umbraco.Media(page.imgPanel).Url" inside the img tag, because when commenting this row, the code works. Any ideas?

  • Paul Wright (suedeapple) 277 posts 704 karma points
    Jun 05, 2017 @ 12:26
    Paul Wright (suedeapple)
    0

    Have you tried just...

    <img src="@page.imgPanel.Url" alt="" />
    

    What kind of property editor are you using for "imgPanel" ?

  • Roger Jarl 22 posts 115 karma points
    Jun 05, 2017 @ 13:29
    Roger Jarl
    0

    @page.imgPanel.Url didn't work. I'm using the Media Picker property editor. I have tried both the obsolete editor and the new one (version 2), without luck.

  • Paul Wright (suedeapple) 277 posts 704 karma points
    Jun 05, 2017 @ 13:44
    Paul Wright (suedeapple)
    100

    Double check all the child nodes to ensure they have an Image selected.

    I'm guessing your code is passing true on

    if (page.HasValue("imgPanel")) {
    

    You may want to put in an extra NULL check as well

    if (page.imgPanel != null) {
    

    Ensure you are using 7.6.3, and set EnablePropertyValueConverters to true, and use the "version2" media type, and resave all your startPage.children nodes.

    And republish the entire site, to clear out the XML cache

  • Roger Jarl 22 posts 115 karma points
    Jun 05, 2017 @ 16:53
    Roger Jarl
    0

    Resaving all my startPage.children nodes and republish the entire site did the trick. Thank you!

  • Anna Maria Serra 2 posts 71 karma points
    Jun 07, 2017 @ 12:41
    Anna Maria Serra
    0

    Hi.

    I have the same problem. Is there a way to save each node in one step or automatically, without opening and saving each node? Because I have a lot of nodes to save and just publishing all doesn't work.

  • Mike Chambers 636 posts 1253 karma points c-trib
    Jun 06, 2017 @ 11:34
    Mike Chambers
    0

    Was hoping that this issue resolved this, as the republishing any and all pages where we need to alter from the legacy to the new media picker is time consuming on large sites.. Also if a page is in an editing cycle, we can't publish the previous version again to generate the UDI :-(

    http://issues.umbraco.org/issue/U4-9974

    "Plus the media picker is missing a check for the obsolete media picker."

                 public override bool IsConverter(PublishedPropertyType propertyType)
             {
    -            return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MediaPicker2Alias);
    +            if (propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MediaPicker2Alias))
    +                return true;
    +
    +            if (UmbracoConfig.For.UmbracoSettings().Content.EnablePropertyValueConverters)
    +            {
    +                return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MediaPickerAlias);
    +            }
    +            return false;
             }
    
             /// <summary>
    
  • Mike Chambers 636 posts 1253 karma points c-trib
    Jun 06, 2017 @ 13:27
    Mike Chambers
    0

    The source to Object convertor only supports UDI's so no go for legacy ints..

    public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
            {
                if (source == null)
                {
                    return null;
                }
    
                var udis = (Udi[])source;
                var mediaItems = new List<IPublishedContent>();
                if (UmbracoContext.Current == null) return source;
                var helper = new UmbracoHelper(UmbracoContext.Current);
                if (udis.Any())
                {
                    foreach (var udi in udis)
                    {
                        var item = helper.TypedMedia(udi);
                        if (item != null)
                            mediaItems.Add(item);
                    }
                    if (IsMultipleDataType(propertyType.DataTypeId, propertyType.PropertyEditorAlias))
                    {
                        return mediaItems;
                    }
                    else
                    {
                        return mediaItems.FirstOrDefault();
                    }
                }
    
                return source;
            }
    

    we could do with a fallback to the

    https://github.com/Jeavon/Umbraco-Core-Property-Value-Converters/blob/v3/Our.Umbraco.PropertyConverters/MediaPickerPropertyConverter.cs

    public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
        {
            if (source == null)
            {
                return null;
            }
    
            if (UmbracoContext.Current != null)
            {
                var media = UmbracoContext.Current.MediaCache.GetById((int)source);
                return ConverterHelper.DynamicInvocation() ? media.AsDynamic() : media;
            }
    
            return null;
        }
    
  • Mike Chambers 636 posts 1253 karma points c-trib
    Jun 07, 2017 @ 10:05
    Mike Chambers
    1

    simple workaround...

            if (Model.HasValue("sectionBanner", true))
            {
                IPublishedContent MediaNode;
                try
                {
                    MediaNode = Model.GetPropertyValue<IPublishedContent>("sectionBanner", true);
                }catch
                {
                    // legacy mediapicker stores int not uid so need to fallback
                    MediaNode = Umbraco.TypedMedia(Model.GetProperty("sectionBanner", true).DataValue);
                }
    
                if (MediaNode != null)
                {
    ...
                }
           }
    
  • David Armitage 508 posts 2078 karma points
    Aug 09, 2018 @ 00:38
    David Armitage
    0

    Hi Mike,

    Thanks. This helped for my issue. A good work around.

    Kind Regards David

  • Abdul Rahim 14 posts 84 karma points
    Jan 30, 2019 @ 09:06
    Abdul Rahim
    0

    Hi Mike,

    Works for me.

    I did a migration for news articles. There was thousands of articles and its not possible to resave and publish all the content. Your solution saved that time.

    Thanks for your trick.

  • Shakib 32 posts 134 karma points
    Jun 14, 2017 @ 07:01
    Shakib
    0

    Hello Guys i have the same problem
    and its not possible to resave and publish all the content because site have a thousands of content. i tested the below code and it didn't do the job.

    var cs = ApplicationContext.Current.Services.ContentService;
    foreach(var content in yourListOfContentItems)
    {
        cs.SaveAndPublish(content);
    }
    
  • Mike Chambers 636 posts 1253 karma points c-trib
    Jun 14, 2017 @ 08:27
  • pavel ringelhan 7 posts 78 karma points
    Jul 24, 2017 @ 14:20
    pavel ringelhan
    1

    Hello, I have a similar problem, I try to programmatically add a picture to the media picker and publish the whole content. The special thing is that it shows the images in backofice. The error is not a valid udi at the frontend. My code is:

    var contentService = ApplicationContext.Current.Services.ContentService;
    var childnode = contentService.CreateContent(
                                row["nazev"].ToString(),
                                node.Id,
                                "pobockyAKontakty",
                                0);
    childnode.SetValue("nazevPobockyBanky", row["nazev"].ToString());
                            childnode.SetValue("adresa", row["adresa"].ToString());
                            childnode.SetValue("mesto", mesto);
                            childnode.SetValue("gPS", row["gps"].ToString());
                            childnode.SetValue("oteviracDoba", row["oteviraciDoba"].ToString());
    string originalPath = "Media\\uploadedImages\\c8178864-de30-4c77-b32c-a210d841a856.jpg";
                            IMediaService mediaService = ApplicationContext.Current.Services.MediaService;
                            var newImage = mediaService.CreateMedia("myTestImage", -1, "Image");
                            byte[] buffer = System.IO.File.ReadAllBytes("c:\\c8178864-de30-4c77-b32c-a210d841a856.jpg");
                            MemoryStream strm = new MemoryStream(buffer);
                            newImage.SetValue("umbracoFile", "myNewImage.png", strm);
                            mediaService.Save(newImage);
                            if (System.IO.File.Exists("c:\\c8178864-de30-4c77-b32c-a210d841a856.jpg"))
                            {
                                //System.IO.File.Delete("c:\\c8178864-de30-4c77-b32c-a210d841a856.jpg");
                            }
                            childnode.SetValue("fotka", newImage.Id);
                            contentService.SaveAndPublishWithStatus(childnode);
    

    template:

    var typedMediaPickerSingle = item.GetPropertyValue<IPublishedContent>("fotka");
    
                            if (typedMediaPickerSingle != null)
                            {
    
                               <figure><img src="@typedMediaPickerSingle.Url.ToString()" alt="img" style="height:100%;" /></figure>
                            }
    

    But here:var typedMediaPickerSingle = item.GetPropertyValue

  • Mike Chambers 636 posts 1253 karma points c-trib
    Jul 24, 2017 @ 15:07
    Mike Chambers
    0

    possibly this line..

     childnode.SetValue("fotka", newImage.Id);
    

    you need to set the value to the udi not the id...

     childnode.SetValue("fotka", "umb://media/" + newImage.Key)
    

    untested but I've used a similar approach here...

    https://our.umbraco.org/forum/using-umbraco-and-getting-started/86315-update-to-7623-and-core-property-value-convertors-id-to-uid-aka-mediapicker-to-mediapicker2#comment-273516

  • pavel ringelhan 7 posts 78 karma points
    Jul 24, 2017 @ 16:08
    pavel ringelhan
    0

    This works well. Thank you very much for your advice I've edited the template:

    var typedMediaPickerSingle = item.fotka;
    
  • pavel ringelhan 7 posts 78 karma points
    Jul 24, 2017 @ 16:09
    pavel ringelhan
    0

    This works well. Thank you very much for your advice I've edited the template:

    var typedMediaPickerSingle = item.fotka;
    
  • David Armitage 508 posts 2078 karma points
    Aug 09, 2018 @ 00:31
    David Armitage
    0

    Hey Guys,

    I get the same issue.

    I am populating a image on one of my doc types in code and saving. Using a value from an already existing image.

    1. If I pass in the ID and save it saves ok. When I look in the backend I can see the image and all looks good. When I try and access this in the frontend I get the not a valid UDI.

    2. So if I pass the UDI in when saving the image again its saves fine. But when I look in the backend it doesn't display the image but instead a message saying the image doesn't exist and something about deleted image. It also wont let me navigate to the image in the backend. The strange think is when I try and access this image in the frontend it works fine.

    This is the code I am using to access the image in the frontend

     if (Model.Content.HasValue("openGraphImage") && Model.Content.GetPropertyValue<IPublishedContent>("openGraphImage") != null)
        {
            openGraphImage = Request.Url.Scheme + "://" + Request.Url.Host + Model.Content.GetPropertyValue<IPublishedContent>("openGraphImage").Url;
        }
    
  • Chris 12 posts 84 karma points
    Oct 19, 2018 @ 15:59
    Chris
    0

    I have exactly the same issue, does anyone know if this is a bug?

    edit: Found the solution is not to build the udi as a string.

    Found the solution is not to build the udi as a string

    or

    GuidUdi udi = IMedia.GetUdi();
    IContent.SetValue("images", udi.ToString());
    
  • Sam 26 posts 137 karma points c-trib
    Aug 09, 2018 @ 01:37
Please Sign in or register to post replies

Write your reply to:

Draft