Copied to clipboard

Flag this post as spam?

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


  • Lee Cook 28 posts 60 karma points
    Feb 26, 2012 @ 20:37
    Lee Cook
    0

    Get image url from a Content object

    Hi,

    I want to know how to get a image url from a content object in umbraco 5, outside of a razor view.

    I have abstracted away my repositories like so:

     

        public Feed CreateEditionList(HiveId publicationId)

            {

                var editions = m_context.Application.Hive.QueryContent()

                    .Where(x => x.ContentType.Alias == "edition")

                    .Where(x => x.Id == publicationId)

                    .ToList();

     

                Feed feed = new Feed();

                feed.Entries = new List<Entry>();

                    UmbracoHelper helper = new UmbracoHelper();

                foreach (var edition in editions)

                {

                    feed.Entries.Add(new Entry(){

                        AuthourName = edition.DynamicField(ContentFields.AUTHOUR_NAME),

                        Id = edition.Id.ToFriendlyString(),

                        //Image = 

     

                    });

                }

                return feed;

    }

     

    I saw the umbracoHelper class, which has lots of nice GetMediaUrl methods, but i didn't want to start wiring up all its dependencies inside my repository.

     

    Any suggestions?

     

    Thanks,


    Lee

  • Lee Cook 28 posts 60 karma points
    Mar 05, 2012 @ 23:11
    Lee Cook
    0

    Anyone? Pretty stuck here.

  • Lee Cook 28 posts 60 karma points
    Mar 06, 2012 @ 01:05
    Lee Cook
    0

    ok, got somewhere:

    edition.DynamicField(ContentFields.COVER_IMAGE) returns a long id  string of some kind ...

     

    "storage$net_root$file-uploader$_p__file-uploader$_v__string$_546a124b26874d7e83d6627d0dea8d06$!01.jpg"

     

    How do you turn that into an image url..?

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Mar 06, 2012 @ 08:48
    Matt Brailsford
    0

    Hey Lee,

    You need to use the GetMediaUrl helper method to get a file upload URL. This is due to the fact the security for media is baked in to v5. As you are working outside of a template, you can either contstruct an UmbracoHelper or just use the UrlHelper, but you'll just want to access the GetMediaUrl extention method.

    _urlHelper.GetMediaUrl(entity, propertyAlias);

    Entity is the entity that holds the file upload property, and propertyAlias is the alias of the upload property itself.

    Hope that helps.

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft