How to Allowed file types svg image upload magento 2
Show in system.log
main.ERROR: Unsupported image format. File:
/var/www/html/pub/media//logos_1.svg
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityHow to Allowed file types svg image upload magento 2
Show in system.log
main.ERROR: Unsupported image format. File:
/var/www/html/pub/media//logos_1.svg
This module makes it possible to upload different filetypes inside the WYSIWYG-editor.
The following filetypes are available by default and it is possible to add extra filetypes to the allowed filetypes in the configuration of the module (General > Content Management > WYSIWYG Options > Extra Allowed Filetypes):
Word (doc, docm, docx)
Excel (csv, xml, xls, xlsx)
PDF (pdf)
Compressed Folder (zip, tar)
https://github.com/experius/Magento-2-Module-Experius-WysiwygDownloads
You can edit di.xml And add Following code
<item name="allowed" xsi:type="array">
<item name="svg" xsi:type="string">image/svg</item>
</item>
<item name="image_allowed" xsi:type="array">
<item name="svg" xsi:type="string">image/svg</item>
</item>
<item name="media_allowed" xsi:type="array">
<item name="svg" xsi:type="string">image/svg</item>
</item>
and in backend set what you need like this
The reason SVG's are disabled in Magento 2 by default, is for security reasons such as stored XSS. And I would recommend that you leave them disabled atleast for now until we get better sanitization for them.
You can see an example of this in APPSEC-1673
, where they removed SVGs in the favicon
https://magento.com/security/patches/magento-2016-and-219-security-update
APPSEC-1673
Stored xss using svg images in Favicon.
While you can't upload SVG's via the backend, you can still upload them with FTP and reference them as if you did upload them. This way you still get the benefits of using SVG's but you don't have to deal with the security issues of allowing users to load them.
But if you do still want to enable SVG upload for the favicon/logo upload. You can create a custom module and override xml nodes/php functions where it was removed from. You can find these in the diff below
https://github.com/magento/magento2/compare/2.1.8...2.1.9
Dependent on where you want to enable SVG uploads will affect what files you will need to override. You should be able to find the files you need to edit by a quick search for allowedExtensions
in XML
files or either getAllowedExtensions
setAllowedExtensions
in PHP
files.
open OR overwrite below file and code <item name="svg" xsi:type="string">text/html</item>
/vendor/magento/module-cms/etc/di.xml
<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>
If you use below magento 2.3 version , code silde change .
Replace above code <item name="svg" xsi:type="string">text/html</item>
To <item name="svg" xsi:type="number">1</item>
Open Below File
/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>