I have the following problem, right now my program uploads the images and does it good, however when i go to the edit product page, the following are empty or uncheked:

  • Role
  • Alt text

Here is the code i use:


namespace Vendor\Module\Model\Adminhtml\Product\MediaGallery;

use \Magento\Catalog\Model\Product\Gallery\EntryFactory;
use \Magento\Catalog\Model\Product\Gallery\GalleryManagement;
use \Magento\Framework\Api\ImageContentFactory;

class ImageUpload extends \Magento\Framework\App\Helper\AbstractHelper

 * @var \Magento\Catalog\Model\Product\Gallery\EntryFactory
private $mediaGalleryEntryFactory;

 * @var \Magento\Catalog\Model\Product\Gallery\GalleryManagement
private $mediaGalleryManagement;

 * @var \Magento\Framework\Api\ImageContentFactory
private $imageContentFactory;

 * @param \Magento\Catalog\Model\Product\Gallery\EntryFactory $mediaGalleryEntryFactory
 * @param \Magento\Catalog\Model\Product\Gallery\GalleryManagement $mediaGalleryManagement
 * @param \Magento\Framework\Api\ImageContentFactory $imageContentFactory
public function __construct(
    EntryFactory $mediaGalleryEntryFactory,
    GalleryManagement $mediaGalleryManagement,
    ImageContentFactory $imageContentFactory
    $this->mediaGalleryEntryFactory = $mediaGalleryEntryFactory;
    $this->mediaGalleryManagement = $mediaGalleryManagement;
    $this->imageContentFactory = $imageContentFactory;

 * @param string $filePath
 * @param string $sku
public function processMediaGalleryEntry($filePath, $sku, $productName, $additional = false, $position = 0)
    $entry = $this->mediaGalleryEntryFactory->create();


        $entry->setTypes(['thumbnail', 'image', 'small_image']);

    $imageContent = $this->imageContentFactory->create();



    $this->mediaGalleryManagement->create($sku, $entry);



What happens in edit page is this:

enter image description here


Can you check the tabel catalog_product_entity_media_gallery_value if the labels are actually created? I had the same problem, the roles and labels were created in a different store view.

Injecting an instance of StoreManagerInterface in your class and calling $this->storeManager->setCurrentStore($storeCode); should solve this problem.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.