Hello Magento Friends,

Hope all are doing great. Today I will be showing How to Display Image in Custom Module using Form Field in Magento 2. Coincidentally, you missed our previously published blog, How to Add Date & Time Picker in Magento 2 System Configuration With Custom Format.

Generally, in Magento 2 grid form, we can put the image upload field but it will not display in the grid as one column. If you want to display the small image in the grid of your custom extension then you need to follow the below steps.

Let’s get started

Steps to Display Image in Custom Module using Form Field in Magento 2:

Step 1: Add new column into InstallSchema.php for image

Step 2: Add Form type must be

enctype=”multipart/form-data” : No characters are encoded. This value is required when you are using forms that have a file upload control.

Step 3: Add field into your form

Step 4: For saving the image, place the code at the below path

app/code/Vendor/Extension/controller/saveimage.php

Step 5: For showing the image into Grid, add this code in your grid file.

Step 6: Create the file Vendor\Extension\Ui\Component\Listing\Column\Thumbnail.php

Step 7: Finally, run the below Magento commands to set up the upgrade and clean cache.

Conclusion:

Hence, this way it is possible to Display Image in Custom Module using Form Field in Magento 2. Finding difficulty in the implementation of the above code? Simply mention in the comment part and I will be pleased to assist you.

Like it? Share it and do not forget to rate the article with 5 stars. Catch you later till then stay tuned!

Happy Coding

Click to rate this post!
[Total: 19 Average: 4.3]