{"id":1963,"date":"2021-11-29T03:30:44","date_gmt":"2021-11-29T03:30:44","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/solved-category-image-deletes-after-initial-save-in-magento-2\/"},"modified":"2025-05-22T09:23:31","modified_gmt":"2025-05-22T03:53:31","slug":"solved-category-image-deletes-after-initial-save-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/solved-category-image-deletes-after-initial-save-in-magento-2\/","title":{"rendered":"Solved: Category Image Deletes After Initial Save in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/meetanshi.com\/magento-2-migration-service.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 migration<\/a>&nbsp;is recommended by experts owing to the security issues in Magento 1. Moreover, the store owner can leverage features like&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-page-builder\/\" target=\"_blank\" rel=\"noreferrer noopener\">page builder<\/a>, enhanced GraphQL, better admin panel, etc. with the latest&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-4-8\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2.4.8<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, sometimes, store owners face issues like&nbsp;<em><strong>category image deletes after initial save in Magento 2<\/strong><\/em>&nbsp;after the site migration. Either the category image uploaded cannot be seen in the frontend or editing the image does not work.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The solution to this issue is given below:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Solution for Category Image Deletes After Initial Save in Magento 2 Issue:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Open&nbsp;<strong><strong>vendor\\magento\\module-catalog\\Model\\Category\\Attribute\\Backend\\Image.php<\/strong><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Edit function&nbsp;<strong>afterSave<\/strong>&nbsp;and put below code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public function afterSave($object)\n    {\n        $value = $object->getData($this->additionalData . $this->getAttribute()->getName());\n \n        if ($this->isTmpFileAvailable($value) &amp;amp;&amp;amp; $imageName = $this->getUploadedImageName($value)) {\n            try {\n                $this->getImageUploader()->moveFileFromTmp($imageName);\n            } catch (\\Exception $e) {\n                $this->_logger->critical($e);\n            }\n        }\n \n        return $this;\n    }<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I suggest that you override this file in any extension, do not directly change it in the vendor folder.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please share the solution with the Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn the programmatic solution to category image deletes after initial save in Magento 2 issue that may be caused after Magento 2 migration.<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1963","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1963"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1963\/revisions"}],"predecessor-version":[{"id":14179,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1963\/revisions\/14179"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}