I need to enable SVG image in upload for custom module.

I have tried all the solution which i have found.

Here is my code:


<type name="Magento\Cms\Model\Wysiwyg\Images\Storage">
           <argument name="extensions" xsi:type="array">
                <item name="allowed" xsi:type="array">
                    <item name="svg" xsi:type="string">text/html</item>
                <item name="image_allowed" xsi:type="array">
                    <item name="svg" xsi:type="string">text/html</item>
                <item name="media_allowed" xsi:type="array">
                    <item name="svg" xsi:type="string">text/html</item>

Any idea? Help will be appreciated.


2 Answers 2


Here you can find a free solution that allows uploading SVG image all over Magento 2: https://github.com/MagestyApps/module-web-images


For magento 2.3 version in etc directory in your module create di.xml file with code

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\MediaStorage\Model\File\Validator\NotProtectedExtension">
        <plugin sortOrder="1" name="RemoveSvgFromNotProtectedExtension" type="Vendor\Module\Plugin\Model\File\Validator\NotProtectedExtension"/>
    <virtualType name="Magento\Catalog\CategoryImageUpload" type="Magento\Catalog\Model\ImageUploader">
            <argument name="allowedExtensions" xsi:type="array">
                <item name="svg" xsi:type="string">svg</item>
            <argument name="allowedMimeTypes" xsi:type="array">
                <item name="svg" xsi:type="string">image/svg</item>

and create plugin file Vendor\Module\Plugin\Model\File\Validator\NotProtectedExtension.php with code


namespace Vendor\Module\Plugin\Model\File\Validator;

class NotProtectedExtension

 * Remove svg from Not Protected Extensions
 * @param \Magento\MediaStorage\Model\File\Validator\NotProtectedExtension $extension
 * @param array $result
 * @return array
public function afterGetProtectedFileExtensions(
    \Magento\MediaStorage\Model\File\Validator\NotProtectedExtension $extension,
) {
    if (in_array('svg', $result)) {
    return $result;

thats all)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.