3

It's an Web API project, to provide some data for third parties.

var image = new MediaItem(imageField.MediaItem);
string src = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(image));

This only get a relative url like "/en/-/media/myrestaurant/home-image-carousel-1.jpg"

How can I get the full path of this iamge? something like GetFriendlyUrl() for a general link which I can get a full path of it as https://local.xxrestaurant:443/en/about-us ?

1 Answer 1

2

you have to use MediaUrlOptions and to pass it to GetMediaUrl method.

You will have:

            var image = new MediaItem(imageField.MediaItem);
            MediaUrlOptions mediaUrlOptions = new MediaUrlOptions();
            mediaUrlOptions.AlwaysIncludeServerUrl = true;
            string src = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(image,mediaUrlOptions));
1
  • Thanks, that really helps.
    – wtf512
    May 8, 2020 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.