32 private $uploaderFactory;
72 private $allowedMimeTypes = [
94 \
Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory,
96 \Psr\Log\LoggerInterface
$logger,
103 $this->uploaderFactory = $uploaderFactory;
187 return rtrim(
$path,
'/') .
'/' . ltrim($imageName,
'/');
208 $this->coreFileStorageDatabase->copyFile(
212 $this->mediaDirectory->renameFile(
216 }
catch (\Exception $e) {
217 throw new \Magento\Framework\Exception\LocalizedException(
218 __(
'Something went wrong while saving the file(s).')
234 public function saveFileToTmpDir($fileId)
239 $uploader = $this->uploaderFactory->create([
'fileId' => $fileId]);
241 $uploader->setAllowRenameFiles(
true);
242 if (!$uploader->checkMimeType($this->allowedMimeTypes)) {
243 throw new \Magento\Framework\Exception\LocalizedException(
__(
'File validation failed.'));
249 throw new \Magento\Framework\Exception\LocalizedException(
250 __(
'File can not be saved to the destination folder.')
257 $result[
'tmp_name'] = str_replace(
'\\',
'/',
$result[
'tmp_name']);
258 $result[
'url'] = $this->storeManager
261 \
Magento\Framework\UrlInterface::URL_TYPE_MEDIA
269 }
catch (\Exception $e) {
270 $this->logger->critical($e);
271 throw new \Magento\Framework\Exception\LocalizedException(
272 __(
'Something went wrong while saving the file(s).')
setAllowedExtensions($allowedExtensions)
getFilePath($path, $imageName)
__construct(\Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase, \Magento\Framework\Filesystem $filesystem, \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Psr\Log\LoggerInterface $logger, $baseTmpPath, $basePath, $allowedExtensions)
setBaseTmpPath($baseTmpPath)
moveFileFromTmp($imageName)