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.
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.
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
Anyone? Pretty stuck here.
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..?
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.
Entity is the entity that holds the file upload property, and propertyAlias is the alias of the upload property itself.
Hope that helps.
Matt
is working on a reply...