Take a look at vendor/magento/module-catalog/etc/di.xml
<virtualType name="Magento\Catalog\CategoryImageUpload" type="Magento\Catalog\Model\ImageUploader">
<arguments>
<argument name="baseTmpPath" xsi:type="string">catalog/tmp/category</argument>
<argument name="basePath" xsi:type="string">catalog/category</argument>
<argument name="allowedExtensions" xsi:type="array">
<item name="jpg" xsi:type="string">jpg</item>
<item name="jpeg" xsi:type="string">jpeg</item>
<item name="gif" xsi:type="string">gif</item>
<item name="png" xsi:type="string">png</item>
</argument>
</arguments>
</virtualType>
In this case, we need to override Magento\Catalog\CategoryImageUpload
, not Magento\Catalog\Model\ImageUploader
.
Our custom class will be the virtual type class. So, we need to re-inject the dependencies.
Your di.xml
should be:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference
for="Magento\Catalog\CategoryImageUpload"
type="Vendor\Module\Model\Catalog\ImageUploader" />
<virtualType name="Vendor\Module\Model\Catalog\ImageUploader" type="Magento\Catalog\Model\ImageUploader">
<arguments>
<argument name="baseTmpPath" xsi:type="string">catalog/tmp/category</argument>
<argument name="basePath" xsi:type="string">catalog/category</argument>
<argument name="allowedExtensions" xsi:type="array">
<item name="jpg" xsi:type="string">jpg</item>
<item name="jpeg" xsi:type="string">jpeg</item>
<item name="gif" xsi:type="string">gif</item>
<!--<item name="png" xsi:type="string">png</item>-->
</argument>
</arguments>
</virtualType>
</config>