Search code examples
model-view-controllerthumbnailskenticomedia-library

ProviderException while creating MediaFileInfo object in Kentico


I want to get thumbnail from file in Kentico 8.2, so I use method as below:

private void ThumbnailTest()
{
    var siteInfo = SiteInfoProvider.GetSiteInfo(ConfigUtils.Tribes.SiteId);
    MediaLibraryInfo libraryInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(ConfigUtils.Tribes.MediaLibraryID);

    string filePath = string.Format(@"D:\\Kentico\{0}\{1}\Homepage\{2}", siteInfo.SiteName, libraryInfo.LibraryFolder, "top_banner_1.jpg");
    MediaFileInfo fileInfo = new MediaFileInfo(filePath, libraryInfo.LibraryID, libraryInfo.LibraryFolder); // <-- exception occurs here

    var thumbnail = MediaFileInfoProvider.GetImageThumbnail(fileInfo, ConfigUtils.Tribes.MediaLibraryPath, ConfigUtils.Tribes.SiteName);
}

but exception occurs while creating MediaFileInfoObject.

System.Configuration.Provider.ProviderException: Method is only supported if the user name parameter matches the user name in the current Windows Identity.

I use Kentico as a content platform on remote server 'A' and I want to get thumbnail for MVC application from my localhost.

Why this exception occurs and what I'm doing wrong?

Thanks for the suggestions!

UPDATE 1:

MediaFileInfo object searches directory at localhost, but not path at remote server and think this is the main issue.

My application is separate MVC website which needs to get thumbnail of image from other domain (server).

UPDATE 2:

private void ThumbnailTest()
{
    MediaLibraryInfo libraryInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(ConfigUtils.Tribes.MediaLibraryID);
    var mediaFileInfo = MediaFileInfoProvider.GetMediaFileInfo(libraryInfo.LibraryID, "Homepage/top_banner_1.jpg"); // success here, file found!
    var thumbnail = MediaFileInfoProvider.GetImageThumbnail(mediaFileInfo, ConfigUtils.Tribes.MediaLibraryPath, ConfigUtils.Tribes.SiteName, 300, 200, 500); // <-- null occurs here 
}

I'm confused, because according to Kentico documentation method GetImageThumbnail:

Returns image thumbnail from the disk or create a new one if doesn't exist yet.

And I have no idea, why thumbnail is null. It should at least create new thumbnail. Should I now use solution provided by @user6043336 ?


Solution

  • Imho you shouldn`t create new MediaFileInfo like

    MediaFileInfo fileInfo = new MediaFileInfo(filePath, libraryInfo.LibraryID, libraryInfo.LibraryFolder); // <-- exception occurs here
    

    but you should try to get media info from db or fs (depending on your setting) instead. Try to use

    GetMediaFileInfo(int mediaLibraryId, string mediaFilePath) 
    

    from MediaFileInfoProvider class.

    ad. UPDATE 2:

    I`ve checked internal implementation on source code and it returns null only if fileInfo is null or if object on filePath does not exists. Please double check it.