Media library Customization

Alonso Gonzalez asked on January 15, 2018 17:35

Hi there,

I'll like to extend the functionality of the default Media Library, right now Im able to upload image files and it render them properly ( I can see a thumbnail of the image when Im selecting it from the Media Selector ) but if I try uploading an SVG image file I will only get a white square.

Image Text

Currently Image files get a tag and display the thumbnail with no problema, but if an svg is uploaded media library will use an tag. How can I do a proper render of this svg to show in the Media Library and in the Media Selector (basically use instead of icon tag?

Thanks,

Correct Answer

Peter Mogilnitski answered on January 19, 2018 15:02

I had the same issue with svg. Media library must treat svg as an image, so the preview will work You can add this key to web,config: <add key="CMSImageExtensions" value="svg;bmp;gif;ico;png;wmf;jpg;jpeg;tiff;tif" />

Or you can modified the code where the rendereing happens in \CMSModules\MediaLibrary\Controls\MediaLibrary\MediaFileEdit.ascx.cs and there around line 430 in the private void SetupFile() you need to change
if (ImageHelper.IsImage(FileInfo.FileExtension) to if (ImageHelper.IsImage(FileInfo.FileExtension) || FileInfo.FileExtension == ".svg")

P.S. File The App_Data/mimetypes.txt file used to register custom media types was removed in Kentico 10. Read more here

1 votesVote for this answer Unmark Correct answer

Recent Answers


Muhammad Zulkamal Zulkifli answered on January 16, 2018 04:39

Im not sure, BUT You can try edit MediaView.aspx.cs(/CMSModules/MediaLibrary/Controls/MediaLibrary/MediaView.ascx) file at line no : 799.

 // Check if file has a preview
 if (!ImageHelper.IsSupportedByImageEditor(extension))
 {
     // File isn't image and no preview exists - get the default file icon
     parameters.IconClass = UIHelper.GetFileIconClass(extension);
 }
 else
 {
     // Files are obtained from the FS
     if (!data.ContainsColumn("FileURL"))
     {
         parameters.Url = GetItemUrl(arg, true, height, width, maxSideSize);
     }
     else
     {
         parameters.IconClass = UIHelper.GetFileIconClass(extension);
     }
 }
2 votesVote for this answer Mark as a Correct answer

Alonso Gonzalez answered on January 19, 2018 15:34

Ey guys thanks both for your help!! Definetly what I needed !

0 votesVote for this answer Mark as a Correct answer

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