Pregunta

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?

¿Fue útil?

Solución

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>

Otros consejos

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

For Magento 2.3, You have to add this to di.xml of your custom 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="string">image/svg+xml</item>
            </item>
            <item name="image_allowed" xsi:type="array">
                <item name="svg" xsi:type="string">image/svg+xml</item>
            </item>
            <item name="media_allowed" xsi:type="array">
                <item name="svg" xsi:type="string">image/svg+xml</item>
            </item>
        </argument>
    </arguments>
</type>

Here is a free solution that adds the possibility to upload SVG images in Magento: https://github.com/MagestyApps/module-web-images

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top