Magento 2 – How to Get Product Image Path by Product ID

imagemagento2

Hello friends i want to fetch image path like var/www/magento/pub/media
i wand to display image in admin grid i am using rendarar to get image
image path by passing Product id. How this can be achieved ? please explain

thanks
Adarsh Shukla

Best Answer

To get media absolute path you can try below code.

public function __construct(
\Magento\Framework\Filesystem\DirectoryList $directoryList

) {
    $this->directory = $directoryList;
}
public function getMediaAbsoluteUrl() {
   $mediaAbsoluteUrl = $this->directory->getPath('media');
}

I hope it'll work for you.

Related Topic