Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I was wondering if there exists an equivalent method for Umbraco.NiceUrlWithDomain( pageId ) to resolve the absolute url for media files?
Thanks! Gert.
Hi Gert,
Try something like this:
var media = Umbraco.TypedMedia(mediaId); url = media.UrlAbsolute();
Thanks
Hi Alex,
The line media.UrlAbsolute() throws the following exception:
'Umbraco.Web.Models.PublishedContentBase' does not contain a definition for 'UrlAbsolute'
I am using the following code in a macro partial:
if ( CurrentPage.HasValue(PropertyAliasNames.OpenGraphImage) ){ var media = Umbraco.TypedMedia(CurrentPage.OpenGraphImage.Id); imageUrl = media.UrlAbsolute(); //imageUrl = VirtualPathUtility.ToAbsolute( "~/" + Umbraco.Media( CurrentPage.OpenGraphImage.Id ).Url );}
The line in comment gives me the relative path, at least on my local host machine.
Regards,
Gert.
Perhaps this post http://stackoverflow.com/questions/6960105/how-do-i-get-the-absolute-media-file-path-in-umbraco-using-razor from StackOverflow can help you finding a solution to get absolute url for your images.
Hope this can help you a step further.
/Dennis
Hi Dennis,
Yes, your are right, but this is not Umbraco solution, .UrlAbsolute() should work at Umbraco 7.1 - 7.2. Because media.NiceUrlWithDomain() is obsolete.
Thanks, Alexander
Hi Alexander,
I am using Umbraco 7.2.1, then why media.UrlAbsolute() throws the exception?
'Umbraco.Web.Models.PublishedContentBase' does not contain a definition for'UrlAbsolute'
Thanks!
The issue here could be that you´re mixing the dynamic and strongly typed razor together.
What if you do it like this:
if (CurrentPage.HasValue(PropertyAliasNames.OpenGraphImage) ){ var media = Umbraco.Media(CurrentPage.OpenGraphImage.Id); imageUrl = media.UrlAbsolute(); //imageUrl = VirtualPathUtility.ToAbsolute( "~/" + Umbraco.Media(CurrentPage.OpenGraphImage.Id ).Url );}
Be aware that I have changed the Umbraco.TypedMedia to just Umbraco.Media which is the dynamic representation.
Hope this helps,
I have the same crash, looks like it's 'AbsoluteUrl is not supported for media types.'. So now we can only use something like told Dennis, and maybe it will work in future releases of Umbraco
Thanks,
Alexander
Same exception.
A low key solution could perhaps be this:
@if (CurrentPage.HasValue(PropertyAliasNames.OpenGraphImage) ){ string domain = "http://" + HttpContext.Current.Request.Url.Host; var media = Umbraco.Media(CurrentPage.OpenGraphImage.Id); <img src="@[email protected]" alt="@media.Name"/>}
Hope this could be a solution for you.
Hi Dennis, that will do the trick! Thanks!
Hi to all,
Is there any better solution for Media Absolute URLs today?
Cheers, Bojan
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Is there an equivalent for Umbraco.NiceUrlWithDomain() for media
I was wondering if there exists an equivalent method for Umbraco.NiceUrlWithDomain( pageId ) to resolve the absolute url for media files?
Thanks! Gert.
Hi Gert,
Try something like this:
var media = Umbraco.TypedMedia(mediaId); url = media.UrlAbsolute();
Thanks
Hi Alex,
The line media.UrlAbsolute() throws the following exception:
I am using the following code in a macro partial:
The line in comment gives me the relative path, at least on my local host machine.
Regards,
Gert.
Hi Gert,
Perhaps this post http://stackoverflow.com/questions/6960105/how-do-i-get-the-absolute-media-file-path-in-umbraco-using-razor from StackOverflow can help you finding a solution to get absolute url for your images.
Hope this can help you a step further.
/Dennis
Hi Dennis,
Yes, your are right, but this is not Umbraco solution, .UrlAbsolute() should work at Umbraco 7.1 - 7.2. Because media.NiceUrlWithDomain() is obsolete.
Thanks, Alexander
Hi Alexander,
I am using Umbraco 7.2.1, then why media.UrlAbsolute() throws the exception?
'Umbraco.Web.Models.PublishedContentBase' does not contain a definition for'UrlAbsolute'
Thanks!
Regards,
Gert.
Hi Gert,
The issue here could be that you´re mixing the dynamic and strongly typed razor together.
What if you do it like this:
Be aware that I have changed the Umbraco.TypedMedia to just Umbraco.Media which is the dynamic representation.
Hope this helps,
/Dennis
I have the same crash, looks like it's 'AbsoluteUrl is not supported for media types.'. So now we can only use something like told Dennis, and maybe it will work in future releases of Umbraco
Thanks,
Alexander
Hi Dennis,
Same exception.
Regards,
Gert.
Hi Gert,
A low key solution could perhaps be this:
Hope this could be a solution for you.
/Dennis
Hi Dennis, that will do the trick! Thanks!
Regards,
Gert.
Hi to all,
Is there any better solution for Media Absolute URLs today?
Cheers, Bojan
is working on a reply...