fileHelper = $fileHelper; $this->fileUploader = $uploaderFactory->create(); $this->fileUploader->init(); $this->fileUploader->setAllowedExtensions($this->getAllowedExtensions()); $this->fileUploader->removeValidateCallback('catalog_product_image'); $this->connection = $resource->getConnection('write'); $this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::ROOT); } /** * Returns an object for upload a media files * * @param string $type * @param array $parameters * @return \Magento\CatalogImportExport\Model\Import\Uploader * @throws \Magento\Framework\Exception\LocalizedException */ public function getUploader($type, $parameters) { $dirConfig = DirectoryList::getDefaultConfig(); $dirAddon = $dirConfig[DirectoryList::MEDIA][DirectoryList::PATH]; if (!empty($parameters[\Magento\ImportExport\Model\Import::FIELD_NAME_IMG_FILE_DIR])) { $tmpPath = $parameters[\Magento\ImportExport\Model\Import::FIELD_NAME_IMG_FILE_DIR]; } else { $tmpPath = $dirAddon . '/' . $this->mediaDirectory->getRelativePath('import'); } if (!$this->fileUploader->setTmpDir($tmpPath)) { throw new \Magento\Framework\Exception\LocalizedException( __('File directory \'%1\' is not readable.', $tmpPath) ); } $destinationDir = "downloadable/files/" . $type; $destinationPath = $dirAddon . '/' . $this->mediaDirectory->getRelativePath($destinationDir); $this->mediaDirectory->create($destinationPath); if (!$this->fileUploader->setDestDir($destinationPath)) { throw new \Magento\Framework\Exception\LocalizedException( __('File directory \'%1\' is not writable.', $destinationPath) ); } return $this->fileUploader; } /** * Get all allowed extensions * * @return array */ protected function getAllowedExtensions() { $result = []; foreach (array_keys($this->fileHelper->getAllMineTypes()) as $option) { $result[] = substr($option, 1); } return $result; } }