Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ....
- protected function getDataUploadField()
- {
- return [
- 'arguments' => [
- 'data' => [
- 'config' => [
- 'componentType' => 'fileUploader',
- 'formElement' => 'fileUploader',
- 'component' => 'Magento_Ui/js/form/element/file-uploader',
- 'dataScope' => 'file',
- 'fileInputName' => 'image',
- 'uploaderConfig' => [
- 'url' => $this->urlBuilder->addSessionParam()->getUrl(
- 'adminhtml/attachements_file/upload'
- ),
- ],
- ],
- ],
- ]
- ];
- }
- ....
- <?php
- namespace VendorModuleControllerAdminhtmlAttachements;
- abstract class File extends MagentoBackendAppAction
- {
- const ADMIN_RESOURCE = 'Magento_Catalog::products';
- }
- <?php
- namespace VendorModuleControllerAdminhtmlAttachementsFile;
- use MagentoBackendAppAction;
- use MagentoFrameworkAppFilesystemDirectoryList;
- class Upload extends VendorModuleControllerAdminhtmlAttachementsFile
- {
- protected $UploaderFactory;
- public function __construct(
- MagentoMediaStorageModelFileUploaderFactory $UploaderFactory,
- ActionContext $context
- ) {
- $this->UploaderFactory = $UploaderFactory;
- parent::__construct($context);
- }
- public function execute(){
- $uploader = $this->UploaderFactory->create(['fileId' => 'image']); //ERROR
- $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
- $uploader->setAllowRenameFiles(false);
- $uploader->setFilesDispersion(false);
- $path = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)
- ->getAbsolutePath('images/');
- $uploader->save($path);
- }
- }
Add Comment
Please, Sign In to add comment