requirejs - How to upload video with browse button in magento 2 admin? -
i have tried place browse button in add video section , unable save video.
please me solve issue.
you need create plugin handle file ,then upload media folder , save url file database
vendor\modulename\model\plugin\adminhtml\product\initialization\helperplugin
<?php namespace vendor\modulename\model\plugin\adminhtml\product\initialization; use \magento\catalog\controller\adminhtml\product\initialization\helper; class helperplugin { protected $mediadirectory; protected $objectmanager; public function __construct( \magento\framework\filesystem $mediadirectory, \magento\framework\objectmanagerinterface $objectmanager ) { $this->mediadirectory = $mediadirectory; $this->objectmanager = $objectmanager; } public function afterinitialize(helper $subject, $result) { if(!empty($_files['product']['name']['yourvideoatributename'])) { $uploader = $this->objectmanager->create('\magento\mediastorage\model\file\uploader', ['fileid' => 'product[yourvideoatributename]']); $mediadirectory = $this->mediadirectory->getdirectoryread(\magento\framework\app\filesystem\directorylist::media); $wrapdir = uniqid(); $filename = $uploader->getcorrectfilename($_files['product']['name']['yourvideoatributename']); $saveresult = $uploader->save($mediadirectory->getabsolutepath('catalog/product/manual/' . $wrapdir), $filename); $result['yourvideoatributename'] = 'catalog/product/yourvideoatributename/' . $wrapdir . '/' . $saveresult['file']; } return $result; } }
vendor\modulename\etc\adminhtml\di.xml
<config> <type name="\magento\catalog\controller\adminhtml\product\initialization\helper"> <plugin name="yourp-initialize-after" type="vendor\modulename\model\plugin\adminhtml\product\initialization\helperplugin"/> </type> </config>
Comments
Post a Comment