Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > How to get secure link from a Media Selection field? View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
John Bubriski - 12/3/2010 3:52:26 PM
   
How to get secure link from a Media Selection field?
It looks like the Media Selection field sets the value to a relative link to the media item, without permissions. Is there any way that I can get a link to the secure version from this field value?

I do NOT want to put a Media control on my page, but instead I need a link to the secure version. I am doing some other things with the link and ONLY need the URL.

I checked out the various helper classes and trasnformations, but didn't find a way to take the relative URL and get the secure version. Any ideas on how to do this?

Thanks,
John

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 12/7/2010 11:38:35 AM
   
RE:How to get secure link from a Media Selection field?
Hello,

I wanted to add a reply here as well (besides the email conversation):

Media selector stores the path in relative format always, difference is that it's either physical path or /getmedia/ path with GUID.
Secured access to the file is possible only through the /getmedia/ link format.
This format is automatically stored when you enable "Use permanent URLs" for Media libraries in SiteManager / Settings, so this is one option how to get the links easily (you would just put it directly into the link).

In case when permanent URLs for media library files are not desired in the whole site, you could get the MediaFileInfo according to given media file path (the relative path).

You can use CMS.MediaLibrary.MediaFileInfoProvider method:

MediaFileInfo GetMediaFileInfo(siteName, mediaFilePath, libraryFolder)
or any of its related overloads (see API Reference)

In this method, query "media.file.selectall" is executed with appropriate where condition using the above parameters, where the mediaFilePath is the relative physical path, libraryFolder is not mandatory (can be null).

This way you could get the media file GUID (from the MediaFileInfo) and use any common method to get the /getmedia/ link...

For the overall solution, you could modify the MediaSelector Form control and ensure and return such /getmedia/ URL for storage into DB (in "Value" get method of the form control).

Regards,
Zdenek

User avatar
Certified Developer v7
Certified  Developer v7
adam - 12/11/2012 12:08:23 PM
   
RE:How to get secure link from a Media Selection field?
i'm using code like this
 MediaFileInfo MediaInfo = MediaFileInfoProvider.GetMediaFileInfo("SiteName", "../medialibrary/site1/Images/garden.jpg", "medialibrary");

this is returning null.

i have hardcoded the values from the db to try and get it to work

i'm using this code in a .ascx control and my site is using kentico version 5.5r2 with portal template.

Thanks

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 12/20/2012 5:46:04 AM
   
RE:How to get secure link from a Media Selection field?
Hi,

Why exactly do you use "../" in the file path? As you specify the library name in the context of the site (determining the folder), you can use just the path inside the library, so something as "/Images/garden.jpg".
Could you please try that?
If this won't help, please provide more information about your media library settings and any other information that could be helpful.

Thanks and regards,
Zdenek