Adding custom Image attribute for category in magento 2
<p>I have tried below code for adding thumbnail image in category.</p>
<p>When i upload image in custom field i get below error.</p>
<p><strong>Error</strong></p>
<blockquote>
<p>Attention</p>
<p>The file was not uploaded.</p>
<p><strong>error: &quot;The file was not uploaded.&quot; errorcode: 666</strong></p>
</blockquote>
<p><strong>category_form.xml</strong></p>
<pre><code>&lt;field name=&quot;thumbnail_image&quot;&gt;
            &lt;argument name=&quot;data&quot; xsi:type=&quot;array&quot;&gt;
                &lt;item name=&quot;config&quot; xsi:type=&quot;array&quot;&gt;
                    &lt;item name=&quot;dataType&quot; xsi:type=&quot;string&quot;&gt;string&lt;/item&gt;
                    &lt;item name=&quot;source&quot; xsi:type=&quot;string&quot;&gt;category&lt;/item&gt;
                    &lt;item name=&quot;label&quot; xsi:type=&quot;string&quot; translate=&quot;true&quot;&gt;Category Image&lt;/item&gt;
                    &lt;item name=&quot;visible&quot; xsi:type=&quot;boolean&quot;&gt;true&lt;/item&gt;
                    &lt;item name=&quot;formElement&quot; xsi:type=&quot;string&quot;&gt;fileUploader&lt;/item&gt;
                    &lt;item name=&quot;elementTmpl&quot; xsi:type=&quot;string&quot;&gt;ui/form/element/uploader/uploader&lt;/item&gt;
                    &lt;item name=&quot;previewTmpl&quot; xsi:type=&quot;string&quot;&gt;Magento_Catalog/image-preview&lt;/item&gt;
                    &lt;item name=&quot;required&quot; xsi:type=&quot;boolean&quot;&gt;false&lt;/item&gt;
                    &lt;item name=&quot;sortOrder&quot; xsi:type=&quot;number&quot;&gt;40&lt;/item&gt;
                    &lt;item name=&quot;uploaderConfig&quot; xsi:type=&quot;array&quot;&gt;
                        &lt;item name=&quot;url&quot; xsi:type=&quot;url&quot; path=&quot;catalog/category_image/upload&quot;/&gt;
                    &lt;/item&gt;
                    &lt;item name=&quot;label&quot; xsi:type=&quot;string&quot; translate=&quot;true&quot;&gt;Thumbnail Image&lt;/item&gt;
                &lt;/item&gt;
            &lt;/argument&gt;
        &lt;/field&gt;
</code></pre>
<p><strong>InstallData.php</strong></p>
<pre><code>$eavSetup-&gt;addAttribute('catalog_category', 'thumbnail_image', array(
    'input'   =&gt; 'image',
    'type'    =&gt; 'varchar',
    'backend' =&gt; 'catalog/category_attribute_backend_image',
    'group' =&gt; 'General',
    'label'         =&gt; 'Thumbnail Image',
    'visible'       =&gt; 1,
    'required'      =&gt; 0,
    'user_defined' =&gt; 1,
    'frontend_input' =&gt;'',
    'global'        =&gt; \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL,
    'visible_on_front'  =&gt; 1,
));
</code></pre>
<p><strong>di.xml</strong></p>
<pre><code>&lt;config xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;../../../../../lib/internal/Magento/Framework/Acl/etc/di.xsd&quot;&gt;
&lt;type name=&quot;Namespace\Module\Controller\Adminhtml\Category\Image&quot;&gt;
    &lt;arguments&gt;
        &lt;argument name=&quot;imageUploader&quot; xsi:type=&quot;object&quot;&gt;Magento\Catalog\CategoryImageUpload&lt;/argument&gt;
    &lt;/arguments&gt;
&lt;/type&gt;
&lt;/config&gt;
</code></pre>