1

I used others post but not working, My currently problem is that I cannot seem.

how can i upload and use SVG file in magento 2.3? please help.

3 Answers 3

1

I believe that you want to use SVG images in cms pages.

For the quick solution got to

[your magento dir]\vendor\magento\module-cms\etc\di.xml

There you can see <type name="Magento\Cms\Model\Wysiwyg\Images\Storage"> add svg to the list like this

<argument name="extensions" xsi:type="array">
<item name="allowed" xsi:type="array">
    <item name="jpg" xsi:type="string">image/jpg</item>
    <item name="jpeg" xsi:type="string">image/jpeg</item>
    <item name="png" xsi:type="string">image/png</item>
    <item name="gif" xsi:type="string">image/gif</item>
    <item name="svg" xsi:type="string">image/svg</item>
</item>
<item name="image_allowed" xsi:type="array">
    <item name="jpg" xsi:type="string">image/jpg</item>
    <item name="jpeg" xsi:type="string">image/jpeg</item>
    <item name="png" xsi:type="string">image/png</item>
    <item name="gif" xsi:type="string">image/gif</item>
    <item name="svg" xsi:type="string">image/svg</item>
</item>
<item name="media_allowed" xsi:type="array">
    <item name="flv" xsi:type="string">video/x-flv</item>
    <item name="swf" xsi:type="string">application/x-shockwave-flash</item>
    <item name="avi" xsi:type="string">video/x-msvideo</item>
    <item name="mov" xsi:type="string">video/x-sgi-movie</item>
    <item name="rm" xsi:type="string">application/vnd.rn-realmedia</item>
    <item name="wmv" xsi:type="string">video/x-ms-wmv</item>
</item>

Hope this helps.

Please note that editing core files are not recommended. Please write it in your custom module.

Don't forget to clear cache

9
  • not working on 2.3 Attention, We don't recognize or support this file extension type.
    – niceonelee
    Commented Mar 1, 2019 at 7:20
  • Did you cleared cache ? Commented Mar 1, 2019 at 7:26
  • I will check it in my local machine and update you Commented Mar 1, 2019 at 7:26
  • YES, i did, but not working
    – niceonelee
    Commented Mar 1, 2019 at 8:01
  • Hi @niceonelee i got solution. Use <item name="svg" xsi:type="string">image/svg+xml</item> instead of <item name="svg" xsi:type="string">image/svg</item> Commented Mar 1, 2019 at 11:23
1

Working fine with M2.3:

app/code/SR/MagentoCommunity/etc/di.xml

<?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\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/plain</item>
                </item>
                <item name="image_allowed" xsi:type="array">
                    <item name="svg" xsi:type="string">text/plain</item>
                </item>
                <item name="media_allowed" xsi:type="array">
                    <item name="svg" xsi:type="string">text/plain</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

[Update]

If this not still not working for you, You can debug what mime type is pass for this.

vendor/magento/framework/File/Uploader.php

/**
 * Used to check if uploaded file mime type is valid or not
 *
 * @param string[] $validTypes
 * @access public
 * @return bool
 */
public function checkMimeType($validTypes = [])
{
    error_log($this->_getMimeType());
    if (count($validTypes) > 0) {
        if (!in_array($this->_getMimeType(), $validTypes)) {
            return false;
        }
    }
    return true;
}

This error_log($this->_getMimeType()); is actual mimetype. Add this type instead text/plain. Mime Type text/plain is for Magento default logo that is use by luma theme.

6
  • may i know where is /SR/MagentoCommunity?vendor/magento ? thank you
    – niceonelee
    Commented Mar 1, 2019 at 9:29
  • You can replace with your own module, in that case your module should load after Magento_Cms module.
    – Sohel Rana
    Commented Mar 1, 2019 at 9:31
  • showing this File validation failed., i added in vendor/magento/module-cms/etc/di.xml
    – niceonelee
    Commented Mar 1, 2019 at 9:36
  • Check updated answer, check your svg file mime type.
    – Sohel Rana
    Commented Mar 1, 2019 at 9:44
  • i added 3 <item name="svg" xsi:type="string">text/plain</item> and error_log($this->_getMimeType()); code , but not work still, can we chat? thank you
    – niceonelee
    Commented Mar 1, 2019 at 10:14
1

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>

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.