Running a successful eCommerce business has a lot to do with the incorporation of minute nuances from the nook and corner of stages like design, development, and implementation. A small hitch in any part of the aspect might have a huge impact on the overall result of the digital business. On that note, not having an essential attribute like File Upload Attribute for Category in Magento 2 made implementation difficult.

There are enough options to upload a File with extensions like JPG, PNG, JPEG, etc in Magento 2, but it was difficult to find the one that could support files with extensions like PDF, TXT, DOC, etc. Enough analyses had to be done to stop this from being a barrier to upload files. Finally, it was sorted out using a code that was exclusively developed for this requirement.

Find the step-by-step code that enables the file upload attribute below.

Implementation of File Upload with Magento 2

Step 1:
Create InstallData.php inside your custom Module. 
Here we have a Module in the name of DCKAP/Category

Inside DCKAP/Category/Setup/InstallData.php

Here we can use Backend option and Input type as Image itself, we can control that later in UI component and di(Dependency Injection).

Step 2:
Create a category_form.xml file on location DCKAP\Category\view\adminhtml\ui_component

Step 3:
Add below code in DCKAP/Category/etc/di.xml
Here we can include the file extension types inside allowedExtensions section.

Step 4:
Create Upload.php file on location DCKAP/Category/Controller/Adminhtml/Category/Manual

DCKAP\Category\Controller\Adminhtml\Category\Manual\Upload
This is a Controller File Where we need to perform our Custom File Upload action

Step 5:
Finally, create DataProvider.php file on location DCKAP\Category\Model\Category

Now it is all done! Once the code is run, an option to upload the file will be included. This is how the exact output looks like.

Screenshot

Be the first to Know

Subscribe to our blog to get the latest articles directly to your inbox.

READY TO DRIVE SALES?

Request a Quote Today

Request a Quote

Leave a Reply

Be the First to Comment!