Copied to clipboard

Flag this post as spam?

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


  • Dennis 33 posts 238 karma points
    Aug 12, 2015 @ 16:11
    Dennis
    0

    Get media URL on server

    Hi I have a REST service (I am using AngularJS) which have e view model, so this model have a Image property, which I would like to add.

    But how do I find the Image Url from the media id?

    I have tried to fizzle around with library.GetMedia(mediaId, false). But this keeps sending me a weird url with some adtional numbers?

    Is there an easy way to get a media url from a media's id from a REST controller?

    So please answer without Razor or XSLT examples :)

  • Jason 122 posts 658 karma points
    Aug 12, 2015 @ 16:57
    Jason
    101

    Have a look at this post:

    https://our.umbraco.org/forum/developers/api-questions/7993-Get-URL-of-media-file

    Bottom line:

    //mediaId is the ID returned from your document property...
    Media file = new Media(mediaId);
    string url = file.getProperty("umbracoFile").Value.ToString();
    

    OR

    var mediaFile = ApplicationContext.Current.Services.MediaService.GetById(1198);
    var url = mediaFile.GetValue("umbracoFile").ToString();
    

    Hope that helps

    JT

  • Dennis 33 posts 238 karma points
    Aug 13, 2015 @ 06:42
    Dennis
    1

    Thank you so much! It was exactly was I was looking for!

    I working in Helper class to my service layer, so getting the context solved some more issues :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies