Want create site? Find Free WordPress Themes and plugins.

Hi, Today I would like to write code snippets to get the media folder URL programmatically in Magento2.

Magento2 stores media data (including images) in the pub/media folder.

The function below returns its url for the current store. The url looks like http://yoursite.com/pub/media/.

/** Get the media folder URL */
function getMediaBaseUrl() {
	$objm = \Magento\Framework\App\ObjectManager::getInstance();
	$storeManager = $objm->get('Magento\Store\Model\StoreManagerInterface');
	$currentStore = $storeManager->getStore();
	return $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
}

Thanks -)

Did you find apk for android? You can find new Free Android Games and apps.

Posted by Abhay Kumar

I am Abhay Kumar from New Delhi (India). I'm working as a Web Developer from last 3+ years. You can follow me on Twitter, Facebook or Google+.