0

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 ?

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));
| improve this answer | |
  • Thanks, that really helps. – wtf512 May 8 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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