Copied to clipboard

Flag this post as spam?

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


  • Nguyen Thi Thu Trang 18 posts 118 karma points
    Feb 07, 2018 @ 12:38
    Nguyen Thi Thu Trang
    0

    Set value media picker from have image url

    I have image url , alias image How to set value media picker ?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Feb 07, 2018 @ 21:17
    Alex Skrypnyk
    1

    Hi Nguyen

    Do you have media Id already? After image upload you have to have media Id, then you can easily set media id to content node media picker like that:

    var node =
    ApplicationContext.Services.ContentService.GetById(productId);
    
    var locaUdi = Udi.Create(Constants.UdiEntityType.Media, media.Key);
    
    node.SetValue( "mediaPicker", locaUdi.ToString() );
    cntsvc.SaveAndPublishWithStatus(node);
    

    Thanks, Alex

  • Nguyen Thi Thu Trang 18 posts 118 karma points
    Feb 21, 2018 @ 10:52
    Nguyen Thi Thu Trang
    0

    Hi Alex

    i see have "media.Key"

    So what is "media"?

  • Nguyen Thi Thu Trang 18 posts 118 karma points
    Feb 08, 2018 @ 01:59
    Nguyen Thi Thu Trang
    0

    Oh again you are. I will try Thank you very much

  • Nguyen Thi Thu Trang 18 posts 118 karma points
    Feb 08, 2018 @ 02:01
    Nguyen Thi Thu Trang
    0

    So, How to get media Id from Url or alias image

  • Nguyen Thi Thu Trang 18 posts 118 karma points
    Feb 08, 2018 @ 08:29
    Nguyen Thi Thu Trang
    0

    I want rename image url when save&public content.

    So media id has not yet?

  • David Armitage 508 posts 2078 karma points
    Jun 21, 2020 @ 04:39
    David Armitage
    0

    If anyone is having trouble with Umbraco 8 then this is how I do it.

    You basically need to get the UDI of the media item and use this to pass into the media picker field.

    var content = _contentService.GetById("content-node-id-here");
    if (content != null)
    {
        content.SetValue("basicStringValue", "some-string-content");
        content.SetValue("anotherBasicStringValue", "some-string-content");
    
        IMedia media = _mediaService.GetById(mediaId);
        if(media != null)
        {
            content.SetValue("logo", media.GetUdi());
        }
    
        if(image != null)
    
    
        _contentService.SaveAndPublish(content);
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft