Copied to clipboard

Flag this post as spam?

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


  • Yajamanam 36 posts 106 karma points
    Mar 26, 2018 @ 15:02
    Yajamanam
    0

    Unable to convert Umbraco image UDI's to a id go get url.

    Hi All,

    I have created restapi service in umrbaco project.i am able to get the data from the api for the particular node.

    I am not able to get media path from image property. ex: instead of your media item having a numeric id, by default it will have an id like this: umb://media/39d3ac707d634953ab52642d5037855c

    below code will works but i don't need reference to umbraco dlls to access the code snippet in the api project. UmbracoHelper uHelper = new UmbracoHelper(UmbracoContext.Current); string mediaUrl = ""; if (CurrentPage.HasValue(propertyName)) { var mediaItem = uHelper.Media(CurrentPage.propertyName.ToString()); mediaUrl = mediaItem.umbracoFile; } return mediaUrl;

    it should return imageurl and content properties in json.

    can you please help me on this.

    thanks, Pradeep

  • Mila Pandurska 43 posts 190 karma points
    Mar 28, 2018 @ 22:09
    Mila Pandurska
    1

    Hi Yajamanam, You have to parse this string to UDi - something like this:

    string imgValue="umb://media/39d3ac707d634953ab52642d5037855c";
     Udi mainImageUdi;
     if (Udi.TryParse(imgValue, out mainImageUdi))
      {
           var mediaItem = _uHelper.TypedMedia(mainImageUdi);
            if (mediaItem != null)
            {
                //this the url of your image without the domain
               return  mediaItem.Url;
            }
       }
    

    Above mediaItem is of type IPublishedContent so you can get the properties that you need.

  • Yajamanam 36 posts 106 karma points
    Apr 04, 2018 @ 14:28
    Yajamanam
    0

    Thanks Mila,

    but i don't need reference to any of umbraco dlls to access the code snippet in the api project.

    if i add UmbracoHelper(UmbracoContext.Current); context will not be available in this project.

    • if use umbracohelper need to refer umbraco dll . is there any other way to get media url without TypedMedia.

    Thanks,Pradeep

  • Ronen Rimon 22 posts 124 karma points
    Apr 10, 2018 @ 13:16
    Ronen Rimon
    0

    you can use umbraco core services

    private int GetIdFromUdi(string udi) { // Get the guid from this string. var imageGuidUdi = GuidUdi.Parse(udi);

            // Get the ID of the node!
            return ApplicationContext.Current.Services.EntityService.GetIdForKey(imageGuidUdi.Guid, (UmbracoObjectTypes)Enum.Parse(typeof(UmbracoObjectTypes), imageGuidUdi.EntityType, true)).Result;
        }
    
  • Yajamanam 36 posts 106 karma points
    Apr 12, 2018 @ 07:08
    Yajamanam
    0

    There still seems to be some confusion about the request.

    1. We have a core product which is hosted in Umbraco but apart from this we also have few light weight applications (not hosted on Umbraco) which only use Html + Knockout + Ajax calls. For these light weight application the only way to get the content from Umbraco portal is via the REST API calls.
    2. In this case we are having issues with the media files as they cannot convert the uid to an image (because they are not on Umbraco and so there is no question of applicationcontext here). We are looking for a way in the REST API to convert the uid to an image path.
  • Ronen Rimon 22 posts 124 karma points
    Apr 15, 2018 @ 08:22
    Ronen Rimon
    0

    In order to get the image url directly, you need:

    1. get the image key (guid) from the udi, in your case umb://media/39d3ac707d634953ab52642d5037855c the guid will be 39d3ac70-7d63-4953-ab52-642d5037855c (you need to format it, the number of chars is 8-4-4-12)

    2. execute sql statement

    select * from cmsContentXml where [xml] like '%39d3ac70-7d63-4953-ab52-642d5037855c%'

    then you will get the xml which includes the image src url,

    just split the result xml string, something like: string imageUrl = resultXml.Split(new string[] { "\"src\":", "," }, StringSplitOptions.RemoveEmptyEntries)[0];

Please Sign in or register to post replies

Write your reply to:

Draft