Accessing Media Library files with getmedia across multiple sites

Delford Chaffin asked on July 15, 2015 21:00

I have two sites sharing some content and all is well until an asset from a media library is called using the getmedia function. For example, the top link below works while the bottom one returns a 404 ...

http://naturalawn.com/getmedia/c0b733f7-8ce6-45bc-9e79-7e82a561d2f2/mower.aspx?width=250&height=250

http://natural-alternative.com/getmedia/c0b733f7-8ce6-45bc-9e79-7e82a561d2f2/mower.aspx?width=250&height=250

Why should this not work? Or should it and I have something set incorrectly?

Thanks!

Correct Answer

Delford Chaffin answered on July 29, 2015 21:37

Thanks for the idea, I did something similar except I looped through all the sites (7 in this case) looking for the file:

fileInfo = (fileInfo ?? MediaFileInfoProvider.GetMediaFileInfo(fileGuid, CurrentSiteName));
if (fileInfo == null)
{
    InfoDataSet<SiteInfo> _sites = SiteInfoProvider.GetAllSites();
    foreach(SiteInfo s in _sites)
    {
        fileInfo = (fileInfo ?? MediaFileInfoProvider.GetMediaFileInfo(fileGuid, s.SiteName));
        if (fileInfo != null)
        {
            break;
        }
    }
}
if (fileInfo != null)
{
    ....
0 votesVote for this answer Unmark Correct answer

Recent Answers


Petr Jiroušek answered on July 23, 2015 08:28

Hi Delford, you are doing it all correctly.

This is default behavior. Media libraries are site specific. However there are quite simple workarounds.

  1. you use direct path. In which case your file is not processed through Kentico, but server from the file system. Unfortunately, in this case you are loosing ability to resize on fly.
  2. small customization in Kentico GetMediaFile.aspx file. I would recommend to make a copy instead of modifying the original file. You need to change line 161 from current site name to hardcoded value of the site with shared images. Finally you will be able to access file through your custom path like: ~/path/mycustompage.aspx?fileguid=84fa8705-2d4c-4086-a748-33737adfa0cd&width=100

    Code to change: var file = MediaFileInfoProvider.GetMediaFileInfo(fileGuid, CurrentSiteName);

Please note: You better replace all 'CurrentSiteName' values in your file to the hardcoded site value.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.