How to obtain url for media item?

Topics: General
Apr 18, 2011 at 4:44 AM

I am trying out Composite C1 for a website that will let people listen to episodes of a local radio show. I am customizing the community blog package so that it will render a player for an MP3.

How do I obtain the URL of an uploaded media file, if I have a reference to the file in a data item?

Thanks for your time.

Apr 18, 2011 at 7:27 AM

Hello,

The URL that deliver images from the Media Archive have next format:

 /Renderers/ShowMedia.ashx?id={Guid}[resizing options]

URL can contain parameters w, h, mw, mh (width, height, max width, max height). When any of these parameters are provided a server side image resizing will be executed on the image. The feature can be used for generating thumbnails.

Example: <img src="/Renderers/ShowMedia.ashx?id={Guid}&mw=500&mh=700"  />

Apr 18, 2011 at 10:28 AM

IMediaFile file = ...; // Get IMediaFile f.e. from DataConnection class string url = Composite.Core.WebClient.MediaUrlHelper.GetUrl(file);

 

Apr 18, 2011 at 4:36 PM

Thank you. I see how that works for C#. Is there a way to do the same thing in an XSLT function?

Apr 18, 2011 at 9:40 PM

The format  that Inna suggested should work:

~/Renderers/ShowMedia.ashx?id={id}

Where {id} could be it one of 3 formats:

a) {Guid}

b) MediaArchive:{Guid}

c) MediaArchive:/MediaFolder/SomeFile.mp3

Even if we will change media url format in future releases (f.e. to /Media/{Guid}/{File name} ) we will still be supporting old media urls, so it is safe to use it

Apr 18, 2011 at 9:49 PM

Interesting with option a, i wasn't aware of that one... IMO that should be default since its much more human readable and seo friendly than just a GUID that doesn't tell much about the file its pointing to,

Apr 19, 2011 at 1:41 AM

Thank you for the explanation.