How to upload webp image in Sitecore CMS

Sitecore don't support webp extension to upload in media library. We need to customize sitecore to enable to upload webp extension. We need to create webp items in Media folder in Template section of content tree, as per below step in master database.

Duplicate  below two items in CMS with name webp:

1. /sitecore/templates/System/Media/Unversioned/Jpeg 

Enter webp in name popup which comes after clicking duplicate option. 

 


path of new item: /sitecore/templates/System/Media/Unversioned/webp







2.  /sitecore/templates/System/Media/Versioned/Jpeg

Enter webp in name popup which comes after clicking duplicate option. 







path of new item: /sitecore/templates/System/Media/Versioned/webp







We need to create a config patch file   /Include/Foundation/*ProjectName*/CustomImageExtension.config with below line :  

















<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
 <mediaLibrary>
    <mediaTypes>
      <mediaType name="webp image" extensions="webp" patch:after="mediaType[@name='XLS File']">
        <mimeType>image/webp</mimeType>
        <forceDownload>false</forceDownload>
        <sharedTemplate>system/media/unversioned/webp</sharedTemplate>
        <versionedTemplate>system/media/versioned/webp</versionedTemplate>
        <mediaValidator type="Sitecore.Resources.Media.ImageValidator" />
        <thumbnails>
          <generator type="Sitecore.Resources.Media.ImageThumbnailGenerator, Sitecore.Kernel">
            <extension>png</extension>
          </generator>
          <width>150</width>
          <height>150</height>
          <backgroundColor>#FFFFFF</backgroundColor>
        </thumbnails>
        <prototypes>
          <media type="Sitecore.Resources.Media.ImageMedia, Sitecore.Kernel" />
        </prototypes>
      </mediaType>
    </mediaTypes>
  </sitecore>
  </sitecore>
</configuration>

Comments

  1. It was very helpful to me as I was facing the problem in uploading webP image in sitecore CMS.

    ReplyDelete
    Replies
    1. I'm facing the webp image uploading issue, sitecore logs are as below:

      Exception: System.ArgumentException
      Message: Parameter is not valid.
      Source: System.Drawing
      at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
      at Sitecore.Resources.Media.ImageMedia.GetImage()
      at Sitecore.Resources.Media.ImageMedia.UpdateImageMetaData(MediaStream mediaStream)
      at Sitecore.Resources.Media.MediaCreator.AttachStreamToMediaItem(Stream stream, String itemPath, String fileName, MediaCreatorOptions options)
      at Sitecore.Resources.Media.MediaCreator.CreateFromStream(Stream stream, String filePath, MediaCreatorOptions options)
      at Sitecore.Resources.Media.MediaUploader.UploadToDatabase(List`1 list)
      at Sitecore.Resources.Media.MediaUploader.Upload()
      at Sitecore.Pipelines.Upload.Save.Process(UploadArgs args)


      can you please provide a solution for this?

      Delete
  2. I tried the above customization to implement the webp-format image upload in the Sitecore media library. After adding the patch file, when I tried to upload the webp image in the media library, a new image item was created, but an error occurred message was shown in the alert popup. Below is an exception logged in Sitecore logs.
    Exception: System.ArgumentException
    Message: Parameter is not valid.
    Source: System.Drawing
    at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
    at Sitecore.Resources.Media.ImageMedia.GetImage()
    at Sitecore.Resources.Media.ImageMedia.UpdateImageMetaData(MediaStream mediaStream)
    at Sitecore.Resources.Media.MediaCreator.AttachStreamToMediaItem(Stream stream, String itemPath, String fileName, MediaCreatorOptions options)
    at Sitecore.Resources.Media.MediaCreator.CreateFromStream(Stream stream, String filePath, MediaCreatorOptions options)
    at Sitecore.Resources.Media.MediaUploader.UploadToDatabase(List`1 list)
    at Sitecore.Resources.Media.MediaUploader.Upload()
    at Sitecore.Pipelines.Upload.Save.Process(UploadArgs args)


    Exception: System.ArgumentException
    Message: Parameter is not valid.
    Source: System.Drawing
    at System.Drawing.Bitmap..ctor(Stream stream)
    at Sitecore.Resources.Media.ImageEffectsResize.ResizeImageStream(Stream inputStream, TransformationOptions options, ImageFormat outputFormat)
    at Sitecore.Resources.Media.ImageThumbnailGenerator.GetStream(MediaData mediaData, TransformationOptions options)
    at Sitecore.Resources.Media.MediaData.GetThumbnailStream(TransformationOptions options)
    at Sitecore.Resources.Media.ThumbnailProcessor.Process(GetMediaStreamPipelineArgs args)
    at (Object , Object )
    at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
    at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)
    at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
    at Sitecore.Resources.Media.Media.GetStreamFromPipeline(MediaOptions options, Boolean& canBeCached)



    ReplyDelete
  3. I'm facing the same issue as mentioned above, can you please provide a solution for it?

    ReplyDelete

Post a Comment

Popular posts from this blog

Sitecore Docker Container Installation and running Sitecore Experience Platform - Single (XP0)

How to enable custom logger in Sitecore