Copied to clipboard

Flag this post as spam?

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


  • How Do I Delete My Account? 68 posts 433 karma points
    Jul 27, 2015 @ 11:19
    How Do I Delete My Account?
    0

    Save an image and then get its path?

    Hi Umbraco Developers!

    I've successfully saved an image through the Services.MediaServices-API. I've also successfully saved an image cropper value to a page (if I have the path/url to the image). What I can't figure out is how to get the newly saved image's URL?

    I've tried several things, like calling Services.MediaServices.GetById(XXXX).Path and also some variants with .umbracoFile - nothing works.

    Any pro out there who can shed some light ?

  • Kevin Jump 2348 posts 14896 karma points MVP 8x c-trib
    Jul 27, 2015 @ 11:45
    Kevin Jump
    100

    Hi,

    once you have saved a media item and want to present it to the front end, then using the UmbracoHelper should work, (so in a partial or macro)

    var media = Umbraco.TypedMedia(xxx) 
    var imgPath = media.GetPropertyValue("umbracoFile") 
    

    should return the virtual path (like "/media/1092/image.gif")

    however if you want to say in the back office with the services, you can access it via GetValue so

    var item = Services.MediaService.GetById(xxx);
    var filePath = item.GetValue<string>("umbracoFile");
    

    this will still be the virtual path, so you might need to map it. in the umbraco back office IOHelper can do that.

    string fullpath = IOHelper.MapPath(string.Format("~{0}", filePath));
    

    *All of the above assumes you are not using the image cropper, - as that stores JSON in the umbracoFile property.

  • How Do I Delete My Account? 68 posts 433 karma points
    Jul 27, 2015 @ 11:59
    How Do I Delete My Account?
    0

    Kevin! You're officially the best! Thx a bunch!

  • 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