2

how can I upload SVG files(icons for example) to my cms Page.

If I try to upload them by using "insert image" and upload them to my media storage I always get "Disallowed file type"?

Is there any way to allow the upload of SVG files?

  • show what you tried ? – Priyank Oct 22 '16 at 7:17
  • I am not sure what you mean by that? I tried to upload a .svg file through the magento 2 backend. Content->Page->MyPage->Content Tab->Insert Image.. – TrytoFly Oct 22 '16 at 8:58
  • 1
    keep in mind that svgs are disabled for security reasons. they can contain malicious javascript code. – Claudiu Creanga Oct 22 '16 at 9:39
  • Oh, ok I actually did not knew that, thank you! Although I can not really refrain from .svg´s in general. – TrytoFly Oct 22 '16 at 19:37
  • I have tried as you said but it is not working – Jaisa Aug 21 '18 at 2:59
2

Go To File: <your magento dir>/vendor/magento/module-cms/etc/di.xml

Add your extension you want to allow <item name="svg" xsi:type="number">1</item>

<argument name="extensions" xsi:type="array">
    <item name="allowed" xsi:type="array">
        <item name="jpg" xsi:type="number">1</item>
        <item name="jpeg" xsi:type="number">1</item>
        <item name="png" xsi:type="number">1</item>
        <item name="gif" xsi:type="number">1</item>
        <item name="svg" xsi:type="number">1</item>
    </item>
    <item name="image_allowed" xsi:type="array">
        <item name="jpg" xsi:type="number">1</item>
        <item name="jpeg" xsi:type="number">1</item>
        <item name="png" xsi:type="number">1</item>
        <item name="gif" xsi:type="number">1</item>
    </item>
    <item name="media_allowed" xsi:type="array">
        <item name="flv" xsi:type="number">1</item>
        <item name="swf" xsi:type="number">1</item>
        <item name="avi" xsi:type="number">1</item>
        <item name="mov" xsi:type="number">1</item>
        <item name="rm" xsi:type="number">1</item>
        <item name="wmv" xsi:type="number">1</item>
    </item>
</argument>
  • 1
    how to do the same not changing the core file? is there any way to rewrite it? – Aleksey Razbakov Feb 1 '17 at 9:44
  • 3
    changing Magento core files is REALLY bad practice, especially when you can extend instead. Dmitry's solution is way better. – Dmitri Sologoubenko Aug 18 '17 at 17:28
  • It allowed svg , but failed to save and not showing the image preview also – Jaisa Aug 21 '18 at 6:41
  • To those reading: please do not do this. You should never edit Composer files like this – Leland Feb 5 at 17:07
7

If you wan't change core files add this to di.xml of your module

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

For magento 2.3 a bit different:

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

It isn't clear solution - there will be some errors in admin, but at least it allows you to upload what you want

  • 1
    The item parameter type changed to string recently with a mime-type value, e.g. <item name="svg" xsi:type="string">image/svg+xml</item> – Zifius Oct 10 '18 at 5:55
  • not working - Magento ver. 2.2.6 – Marina Voronova Oct 15 '18 at 3:47
  • 1
    It's no longer working in 2.3 and I suggest whoever wants to use svg to simply give it up. Looks like Magento is determined to phase out svg for security reasons: magento.com/security/patches/… – Ethan Wan Feb 1 at 1:07
  • how can working in 2.3? thank you! @EthanWan – niceonelee Mar 1 at 6:24
  • @niceonelee, I've updated the answer – Dmitry Mar 1 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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