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
|