Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rasmus Eeg 91 posts 457 karma points c-trib
    Jul 30, 2015 @ 09:36
    Rasmus Eeg
    0

    Custom ThumbnailProvider not working?

    Hello world!

    I'm trying to create an handler for retreiving thumbnails for pdf files. This is what i've got so far:

      public class PdfThumbnailProvider : AbstractThumbnailProvider
      {
        protected override IEnumerable<string> SupportedExtensions
        {
          get { return new List<string> { ".pdf" }; }
        }
    
        protected override bool TryGetThumbnailUrl(string fileUrl, out string thumbUrl)
        {
          // Set thumbnail url to empty strin initially
          thumbUrl = string.Empty;
    
          // Make sure file has an extension
          var ext = Path.GetExtension( fileUrl );
          if( string.IsNullOrEmpty( ext ) )
            return false;
    
          // Make sure it has a supported file extension
          if( !IsSupportedExtension( ext ) )
            return false;
    
          // Make sure the thumbnail exists
          var tmpThumbUrl = fileUrl.Replace( ext, "_thumb.jpg" );
    
          try
          {
            var fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
            var relativeThumbPath = fs.GetRelativePath( tmpThumbUrl );
            if( !fs.FileExists( relativeThumbPath ) )
              return false;
          }
          catch( Exception )
          {
            // If something odd happens, just return false and move on
            return false;
          }
    
          // We've got this far, so thumbnail must exist
          thumbUrl = tmpThumbUrl;
          return true;
        }
      }
    

    But this isn't working, what am i missing?

    I've based in on this source: https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Web/Media/ThumbnailProviders/ImageThumbnailProvider.cs

    Best regards Rasmus E.

    -- UPDATE:

    Found the following ThumbnailProvidersResolver, but it turns out this is internal sealed and not public sealed like the ContentFinderResolver

    I've created a pull-request here: https://github.com/umbraco/Umbraco-CMS/pull/751

    And issue here: http://issues.umbraco.org/issue/U4-6902?query=ThumbnailProvider

  • Rasmus Eeg 91 posts 457 karma points c-trib
    Jul 30, 2015 @ 13:08
    Rasmus Eeg
    100

    The pull-request has been accepted and is now due in v7.3.0

Please Sign in or register to post replies

Write your reply to:

Draft