2

I've added attribute to my category following this guide (https://belvg.com/blog/how-to-add-image-attribute-to-a-category-in-magento-2.html).

Looks like I am on right way, but when I try to upload image, I receive 404 error in my chrome console:

POST http://mywebsite.com/admin/VendorName_CategoryImage/category_thumb/upload/key/48f549e227d66a94210827868a615957af8239355508cfad904f1da8444baaef/?isAjax=true 404 (Forbidden)

I think that troubles in my app/code/VendorName/CategoryImage/view/adminhtml/ui_component/category_form.xml:

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="content">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Content</item>
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="sortOrder" xsi:type="number">90</item>
            </item>
        </argument>
        <field name="image_thumb">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="source" xsi:type="string">category</item>
                    <item name="label" xsi:type="string" translate="true">Mobile Image</item>
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="formElement" xsi:type="string">fileUploader</item>
                    <item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
                    <item name="previewTmpl" xsi:type="string">Magento_Catalog/image-preview</item>
                    <item name="required" xsi:type="boolean">false</item>
                    <item name="sortOrder" xsi:type="number">40</item>
                    <item name="uploaderConfig" xsi:type="array">
                        <item name="url" xsi:type="url" path="VendorName_CategoryImage/category_thumb/upload"/>
                    </item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>

Thanks for any help!

1 Answer 1

3

I think you should add your router name in app/code/VendorName/CategoryImage/view/adminhtml/ui_component/category_form.xml: file,

 <item name="uploaderConfig" xsi:type="array">
                        <item name="url" xsi:type="url" path="VendorName_CategoryImage/category_thumb/upload"/>
                    </item>

replace VendorName_CategoryImage with your extension router name, you can find route.xml file from

app/code/VendorName/CategoryImage/etc/adminhtml/routes.xml

If you don't have routes.xml file in your module then just create it with unique route name.

routes.xml file looks like this

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route id="YOUR_ID" frontName="YOUR_ROUTE_NAME">
            <module name="VendorName_CategoryImage" before="Magento_Backend" />
        </route>
    </router>
</config>

replace YOUR_ROUTE_NAME,YOUR_ID

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.