Magento 2 Module


How to upload an image using fileUploader in Magento 2


Hide/Show description

Hi Everybody, I am Cuong, Welcome to my Magento 2 Tutorial video series. #magento2tutorial In the previous lessons, I showed everyone: 1. How to create a new module in Magento 2, at the video link https://www.youtube.com/watch?v=JwxtiEwEZpk 2. How to add new tables for a custom module in Magento 2, at the video link https://www.youtube.com/watch?v=gtSx1BUxYtw 3. How to create an adminhtml grid using UI component in Magento 2, at the video link https://www.youtube.com/watch?v=qeIjXiAI5JY 4. How to create a form using UI component in Magento 2, at the video link https://www.youtube.com/watch?v=FCgi2-ZB7fA To continue the previous lessons, today, I am going to show everyone, How to upload an image using fileUploader in Magento 2. To complete this exercise you need to complete the following high-level steps: 1. Add the field named image - Add the field named image to the UI Component Form 2. Create the action named Upload - Create the file named Upload.php in the path app\code\PHPCuong\BannerSlider\Controller\Adminhtml\Banner 3. Create the file named ImageUploader.php - Create the file named ImageUploader.php in the path app\code\PHPCuong\BannerSlider\Model\Banner 4. Convert image data to acceptable for rendering format in the UI Component Form 6. Retrieve the Image URL for displaying Add the function for getting the Image URL in the Banner model. 7. Process saving the Image in the action named Save 6. Flush the caches, test and see the results. - php bin/magento cache:flush It works perfectly. Thank you for your watching. If you have any questions about this exercise please feel free to leave a comment below. Don't forget to like, comment, share and subscribe to my channel for getting the latest videos. Please do not hesitate to contact me if you need me to join your Magento project. My rate is $25/hour in Magento 1 and $30/hour in Magento 2. Get the source codes of this tutorial on the github https://github.com/php-cuong/magento2-banners-slider