🔥 Just Launched! Werra Premium Template for HyväSee it in Action

Solved: Category Image Deletes After Initial Save in Magento 2

By Jignesh ParmarUpdated on May 22, 2025 1 min read

Magento 2 migration is recommended by experts owing to the security issues in Magento 1. Moreover, the store owner can leverage features like page builder, enhanced GraphQL, better admin panel, etc. with the latest Magento 2.4.8

However, sometimes, store owners face issues like category image deletes after initial save in Magento 2 after the site migration. Either the category image uploaded cannot be seen in the frontend or editing the image does not work.

The solution to this issue is given below:

Solution for Category Image Deletes After Initial Save in Magento 2 Issue:

Open vendor\magento\module-catalog\Model\Category\Attribute\Backend\Image.php

Edit function afterSave and put below code:

public function afterSave($object)
    {
        $value = $object->getData($this->additionalData . $this->getAttribute()->getName());
 
        if ($this->isTmpFileAvailable($value) && $imageName = $this->getUploadedImageName($value)) {
            try {
                $this->getImageUploader()->moveFileFromTmp($imageName);
            } catch (\Exception $e) {
                $this->_logger->critical($e);
            }
        }
 
        return $this;
    }

That’s it.

I suggest that you override this file in any extension, do not directly change it in the vendor folder.

Please share the solution with the Magento Community via social media.

Thank you.

Jignesh Parmar Full Image
Article byJignesh Parmar

An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.