Magento 2 : Missing required argument $baseTmpPathMagento2 image file in ui component formMagento 2: Where are Gallery Images Processed in an Admin Save?How can i rewrite TierPrice Block in Magento2How to add filtering to custom table field column in Customers admin grid in Magento2?main.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelWhy Getting categories and names on product view page Magento 2 fails?Magento 2.1 Create a filter in the product grid by new attributeMagento offline custom Payment method with drop down listHow to solve Front controller reached 100 router match iterations in magento2What is the correct way to create Mock input interface in Web-Api functional test?Magento 2.3 Can't view module's front end page output?

What are the benefits of cryosleep?

Can a non-EU citizen travel within the Schengen area without identity documents?

What are the slash markings on Gatwick's 08R/26L?

What caused the tendency for conservatives to not support climate change regulations?

Is floating in space similar to falling under gravity?

What does "tea juice" mean in this context?

What's the most polite way to tell a manager "shut up and let me work"?

Get LaTeX form from step by step solution

Points within polygons in different projections

How can I prevent interns from being expendable?

Asking bank to reduce APR instead of increasing credit limit

Creating Fictional Slavic Place Names

How do I subvert the tropes of a train heist?

Modern approach to radio buttons

Can't connect to Internet in bash using Mac OS

Tic-Tac-Toe for the terminal

Is there an evolutionary advantage to having two heads?

Infinitely many hats

Possible nonclassical ion from a bicyclic system

Are there regional foods in Westeros?

Expenditure in Poland - Forex doesn't have Zloty

Is having a hidden directory under /etc safe?

Thousands and thousands of words

How to detach yourself from a character you're going to kill?



Magento 2 : Missing required argument $baseTmpPath


Magento2 image file in ui component formMagento 2: Where are Gallery Images Processed in an Admin Save?How can i rewrite TierPrice Block in Magento2How to add filtering to custom table field column in Customers admin grid in Magento2?main.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelWhy Getting categories and names on product view page Magento 2 fails?Magento 2.1 Create a filter in the product grid by new attributeMagento offline custom Payment method with drop down listHow to solve Front controller reached 100 router match iterations in magento2What is the correct way to create Mock input interface in Web-Api functional test?Magento 2.3 Can't view module's front end page output?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I used image uploader in ui form. But, when I save image not saved in main folder and return error




Missing required argument $baseTmpPath of VendorModuleModelImageUploader.




My Files code :



di.xml :



<!-- Image Uploader -->
<virtualType name="VendorModuleModelImageUploader" type="VendorModuleModelImageUploader">
<arguments>
<argument name="baseTmpPath" xsi:type="string">test/tmp/image</argument>
<argument name="basePath" xsi:type="string">test/image</argument>
<argument name="allowedExtensions" xsi:type="array">
<item name="jpg" xsi:type="string">jpg</item>
<item name="jpeg" xsi:type="string">jpeg</item>
<item name="gif" xsi:type="string">gif</item>
<item name="png" xsi:type="string">png</item>
</argument>
</arguments>
</virtualType>
<type name="VendorModuleControllerAdminhtmlTestUpload">
<arguments>
<argument name="imageUploader" xsi:type="object">VendorModuleModelImageUploader</argument>
</arguments>
</type>
<!-- End Image Uploader -->


ImageUploader.php :



<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace VendorModuleModel;

/**
* Catalog image uploader
*/
class ImageUploader
/**
* Core file storage database
*
* @var MagentoMediaStorageHelperFileStorageDatabase
*/
protected $coreFileStorageDatabase;

/**
* Media directory object (writable).
*
* @var MagentoFrameworkFilesystemDirectoryWriteInterface
*/
protected $mediaDirectory;

/**
* Uploader factory
*
* @var MagentoMediaStorageModelFileUploaderFactory
*/
private $uploaderFactory;

/**
* Store manager
*
* @var MagentoStoreModelStoreManagerInterface
*/
protected $storeManager;

/**
* @var PsrLogLoggerInterface
*/
protected $logger;

/**
* Base tmp path
*
* @var string
*/
protected $baseTmpPath;

/**
* Base path
*
* @var string
*/
protected $basePath;

/**
* Allowed extensions
*
* @var string
*/
protected $allowedExtensions;

/**
* ImageUploader constructor
*
* @param MagentoMediaStorageHelperFileStorageDatabase $coreFileStorageDatabase
* @param MagentoFrameworkFilesystem $filesystem
* @param MagentoMediaStorageModelFileUploaderFactory $uploaderFactory
* @param MagentoStoreModelStoreManagerInterface $storeManager
* @param PsrLogLoggerInterface $logger
* @param string $baseTmpPath
* @param string $basePath
* @param string[] $allowedExtensions
*/
public function __construct(
MagentoMediaStorageHelperFileStorageDatabase $coreFileStorageDatabase,
MagentoFrameworkFilesystem $filesystem,
MagentoMediaStorageModelFileUploaderFactory $uploaderFactory,
MagentoStoreModelStoreManagerInterface $storeManager,
PsrLogLoggerInterface $logger,
$baseTmpPath,
$basePath,
$allowedExtensions
)
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
$this->mediaDirectory = $filesystem->getDirectoryWrite(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
$this->uploaderFactory = $uploaderFactory;
$this->storeManager = $storeManager;
$this->logger = $logger;
$this->baseTmpPath = $baseTmpPath;
$this->basePath = $basePath;
$this->allowedExtensions = $allowedExtensions;


/**
* Set base tmp path
*
* @param string $baseTmpPath
*
* @return void
*/
public function setBaseTmpPath($baseTmpPath)
$this->baseTmpPath = $baseTmpPath;


/**
* Set base path
*
* @param string $basePath
*
* @return void
*/
public function setBasePath($basePath)
$this->basePath = $basePath;


/**
* Set allowed extensions
*
* @param string[] $allowedExtensions
*
* @return void
*/
public function setAllowedExtensions($allowedExtensions)
$this->allowedExtensions = $allowedExtensions;


/**
* Retrieve base tmp path
*
* @return string
*/
public function getBaseTmpPath()
return $this->baseTmpPath;


/**
* Retrieve base path
*
* @return string
*/
public function getBasePath()
return $this->basePath;


/**
* Retrieve base path
*
* @return string[]
*/
public function getAllowedExtensions()
return $this->allowedExtensions;


/**
* Retrieve path
*
* @param string $path
* @param string $imageName
*
* @return string
*/
public function getFilePath($path, $imageName)
return rtrim($path, '/') . '/' . ltrim($imageName, '/');


/**
* Checking file for moving and move it
*
* @param string $imageName
*
* @return string
*
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function moveFileFromTmp($imageName)
$baseTmpPath = $this->getBaseTmpPath();
$basePath = $this->getBasePath();

$baseImagePath = $this->getFilePath($basePath, $imageName);
$baseTmpImagePath = $this->getFilePath($baseTmpPath, $imageName);

try
$this->coreFileStorageDatabase->copyFile(
$baseTmpImagePath,
$baseImagePath
);
$this->mediaDirectory->renameFile($baseTmpImagePath, $baseImagePath);
catch (Exception $e)
throw new MagentoFrameworkExceptionLocalizedException(
__('Something went wrong while saving the file(s).')
);


return $imageName;


/**
* Checking file for save and save it to tmp dir
*
* @param string $fileId
*
* @return string[]
*
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function saveFileToTmpDir($fileId)
$baseTmpPath = $this->getBaseTmpPath();
$uploader = $this->uploaderFactory->create(['fileId' => $fileId]);
$uploader->setAllowedExtensions($this->getAllowedExtensions());
$uploader->setAllowRenameFiles(true);

$result = $uploader->save($this->mediaDirectory->getAbsolutePath($baseTmpPath));

if (!$result)
throw new MagentoFrameworkExceptionLocalizedException(
__('File can not be saved to the destination folder.')
);


$result['tmp_name'] = str_replace('\', '/', $result['tmp_name']);
$result['path'] = str_replace('\', '/', $result['path']);
$result['url'] = $this->storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . $this->getFilePath($baseTmpPath, $result['file']);
$result['name'] = $result['file'];

if (isset($result['file']))
try
$relativePath = rtrim($baseTmpPath, '/') . '/' . ltrim($result['file'], '/');
$this->coreFileStorageDatabase->saveFile($relativePath);
catch (Exception $e)
$this->logger->critical($e);
throw new MagentoFrameworkExceptionLocalizedException(
__('Something went wrong while saving the file(s).')
);



return $result;




Save.php :



private function imageSaveToDir(array $rawData) 
$data = $rawData;
if (isset($data['review_image'][0]['name']) && isset($data['review_image'][0]['tmp_name']))
$data['review_image'] = $data['review_image'][0]['name'];
/** VendorModuleModelImageUploader $imageUploader*/
$this->imageUploader->moveFileFromTmp($data['review_image']);
elseif (isset($data['review_image'][0]['image']) && !isset($data['review_image'][0]['tmp_name']))
$data['review_image'] = $data['review_image'][0]['image'];
else
$data['review_image'] = null;

return $data;



DataProvider.php :



if (!$this->loadedData) 
$storeId = (int) $this->request->getParam('store');
$this->collection->setStoreId($storeId)->addAttributeToSelect('*');
$items = $this->collection->getItems();
foreach ($items as $item)
$itemData = $item->getData();
$imageName = $itemData['review_image'];
$itemData['review_image'] = array(
[
'name' => $imageName,
'url' => $this->storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'test/image/' . $imageName,
],
);
$item->setStoreId($storeId);
$this->loadedData[$item->getEntityId()] = $itemData;
break;




Upload.php :



public function execute() 
$imageUploadId = $this->_request->getParam('param_name', 'review_image');
try
$this->imageUploader->setBaseTmpPath('test/tmp/image');
$this->imageUploader->setBasePath('test/image');
$imageResult = $this->imageUploader->saveFileToTmpDir($imageUploadId);

$imageResult['cookie'] = [
'name' => $this->_getSession()->getName(),
'value' => $this->_getSession()->getSessionId(),
'lifetime' => $this->_getSession()->getCookieLifetime(),
'path' => $this->_getSession()->getCookiePath(),
'domain' => $this->_getSession()->getCookieDomain(),
];
catch (Exception $e)
$imageResult = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];

return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($imageResult);



What I missing here ?



Please help me.



Thanks.










share|improve this question
























  • add contruct method too

    – Sohel Rana
    Mar 16 at 9:17











  • Which file's ? @SohelRana

    – Emipro Technologies Pvt. Ltd.
    Mar 17 at 9:18

















2















I used image uploader in ui form. But, when I save image not saved in main folder and return error




Missing required argument $baseTmpPath of VendorModuleModelImageUploader.




My Files code :



di.xml :



<!-- Image Uploader -->
<virtualType name="VendorModuleModelImageUploader" type="VendorModuleModelImageUploader">
<arguments>
<argument name="baseTmpPath" xsi:type="string">test/tmp/image</argument>
<argument name="basePath" xsi:type="string">test/image</argument>
<argument name="allowedExtensions" xsi:type="array">
<item name="jpg" xsi:type="string">jpg</item>
<item name="jpeg" xsi:type="string">jpeg</item>
<item name="gif" xsi:type="string">gif</item>
<item name="png" xsi:type="string">png</item>
</argument>
</arguments>
</virtualType>
<type name="VendorModuleControllerAdminhtmlTestUpload">
<arguments>
<argument name="imageUploader" xsi:type="object">VendorModuleModelImageUploader</argument>
</arguments>
</type>
<!-- End Image Uploader -->


ImageUploader.php :



<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace VendorModuleModel;

/**
* Catalog image uploader
*/
class ImageUploader
/**
* Core file storage database
*
* @var MagentoMediaStorageHelperFileStorageDatabase
*/
protected $coreFileStorageDatabase;

/**
* Media directory object (writable).
*
* @var MagentoFrameworkFilesystemDirectoryWriteInterface
*/
protected $mediaDirectory;

/**
* Uploader factory
*
* @var MagentoMediaStorageModelFileUploaderFactory
*/
private $uploaderFactory;

/**
* Store manager
*
* @var MagentoStoreModelStoreManagerInterface
*/
protected $storeManager;

/**
* @var PsrLogLoggerInterface
*/
protected $logger;

/**
* Base tmp path
*
* @var string
*/
protected $baseTmpPath;

/**
* Base path
*
* @var string
*/
protected $basePath;

/**
* Allowed extensions
*
* @var string
*/
protected $allowedExtensions;

/**
* ImageUploader constructor
*
* @param MagentoMediaStorageHelperFileStorageDatabase $coreFileStorageDatabase
* @param MagentoFrameworkFilesystem $filesystem
* @param MagentoMediaStorageModelFileUploaderFactory $uploaderFactory
* @param MagentoStoreModelStoreManagerInterface $storeManager
* @param PsrLogLoggerInterface $logger
* @param string $baseTmpPath
* @param string $basePath
* @param string[] $allowedExtensions
*/
public function __construct(
MagentoMediaStorageHelperFileStorageDatabase $coreFileStorageDatabase,
MagentoFrameworkFilesystem $filesystem,
MagentoMediaStorageModelFileUploaderFactory $uploaderFactory,
MagentoStoreModelStoreManagerInterface $storeManager,
PsrLogLoggerInterface $logger,
$baseTmpPath,
$basePath,
$allowedExtensions
)
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
$this->mediaDirectory = $filesystem->getDirectoryWrite(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
$this->uploaderFactory = $uploaderFactory;
$this->storeManager = $storeManager;
$this->logger = $logger;
$this->baseTmpPath = $baseTmpPath;
$this->basePath = $basePath;
$this->allowedExtensions = $allowedExtensions;


/**
* Set base tmp path
*
* @param string $baseTmpPath
*
* @return void
*/
public function setBaseTmpPath($baseTmpPath)
$this->baseTmpPath = $baseTmpPath;


/**
* Set base path
*
* @param string $basePath
*
* @return void
*/
public function setBasePath($basePath)
$this->basePath = $basePath;


/**
* Set allowed extensions
*
* @param string[] $allowedExtensions
*
* @return void
*/
public function setAllowedExtensions($allowedExtensions)
$this->allowedExtensions = $allowedExtensions;


/**
* Retrieve base tmp path
*
* @return string
*/
public function getBaseTmpPath()
return $this->baseTmpPath;


/**
* Retrieve base path
*
* @return string
*/
public function getBasePath()
return $this->basePath;


/**
* Retrieve base path
*
* @return string[]
*/
public function getAllowedExtensions()
return $this->allowedExtensions;


/**
* Retrieve path
*
* @param string $path
* @param string $imageName
*
* @return string
*/
public function getFilePath($path, $imageName)
return rtrim($path, '/') . '/' . ltrim($imageName, '/');


/**
* Checking file for moving and move it
*
* @param string $imageName
*
* @return string
*
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function moveFileFromTmp($imageName)
$baseTmpPath = $this->getBaseTmpPath();
$basePath = $this->getBasePath();

$baseImagePath = $this->getFilePath($basePath, $imageName);
$baseTmpImagePath = $this->getFilePath($baseTmpPath, $imageName);

try
$this->coreFileStorageDatabase->copyFile(
$baseTmpImagePath,
$baseImagePath
);
$this->mediaDirectory->renameFile($baseTmpImagePath, $baseImagePath);
catch (Exception $e)
throw new MagentoFrameworkExceptionLocalizedException(
__('Something went wrong while saving the file(s).')
);


return $imageName;


/**
* Checking file for save and save it to tmp dir
*
* @param string $fileId
*
* @return string[]
*
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function saveFileToTmpDir($fileId)
$baseTmpPath = $this->getBaseTmpPath();
$uploader = $this->uploaderFactory->create(['fileId' => $fileId]);
$uploader->setAllowedExtensions($this->getAllowedExtensions());
$uploader->setAllowRenameFiles(true);

$result = $uploader->save($this->mediaDirectory->getAbsolutePath($baseTmpPath));

if (!$result)
throw new MagentoFrameworkExceptionLocalizedException(
__('File can not be saved to the destination folder.')
);


$result['tmp_name'] = str_replace('\', '/', $result['tmp_name']);
$result['path'] = str_replace('\', '/', $result['path']);
$result['url'] = $this->storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . $this->getFilePath($baseTmpPath, $result['file']);
$result['name'] = $result['file'];

if (isset($result['file']))
try
$relativePath = rtrim($baseTmpPath, '/') . '/' . ltrim($result['file'], '/');
$this->coreFileStorageDatabase->saveFile($relativePath);
catch (Exception $e)
$this->logger->critical($e);
throw new MagentoFrameworkExceptionLocalizedException(
__('Something went wrong while saving the file(s).')
);



return $result;




Save.php :



private function imageSaveToDir(array $rawData) 
$data = $rawData;
if (isset($data['review_image'][0]['name']) && isset($data['review_image'][0]['tmp_name']))
$data['review_image'] = $data['review_image'][0]['name'];
/** VendorModuleModelImageUploader $imageUploader*/
$this->imageUploader->moveFileFromTmp($data['review_image']);
elseif (isset($data['review_image'][0]['image']) && !isset($data['review_image'][0]['tmp_name']))
$data['review_image'] = $data['review_image'][0]['image'];
else
$data['review_image'] = null;

return $data;



DataProvider.php :



if (!$this->loadedData) 
$storeId = (int) $this->request->getParam('store');
$this->collection->setStoreId($storeId)->addAttributeToSelect('*');
$items = $this->collection->getItems();
foreach ($items as $item)
$itemData = $item->getData();
$imageName = $itemData['review_image'];
$itemData['review_image'] = array(
[
'name' => $imageName,
'url' => $this->storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'test/image/' . $imageName,
],
);
$item->setStoreId($storeId);
$this->loadedData[$item->getEntityId()] = $itemData;
break;




Upload.php :



public function execute() 
$imageUploadId = $this->_request->getParam('param_name', 'review_image');
try
$this->imageUploader->setBaseTmpPath('test/tmp/image');
$this->imageUploader->setBasePath('test/image');
$imageResult = $this->imageUploader->saveFileToTmpDir($imageUploadId);

$imageResult['cookie'] = [
'name' => $this->_getSession()->getName(),
'value' => $this->_getSession()->getSessionId(),
'lifetime' => $this->_getSession()->getCookieLifetime(),
'path' => $this->_getSession()->getCookiePath(),
'domain' => $this->_getSession()->getCookieDomain(),
];
catch (Exception $e)
$imageResult = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];

return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($imageResult);



What I missing here ?



Please help me.



Thanks.










share|improve this question
























  • add contruct method too

    – Sohel Rana
    Mar 16 at 9:17











  • Which file's ? @SohelRana

    – Emipro Technologies Pvt. Ltd.
    Mar 17 at 9:18













2












2








2








I used image uploader in ui form. But, when I save image not saved in main folder and return error




Missing required argument $baseTmpPath of VendorModuleModelImageUploader.




My Files code :



di.xml :



<!-- Image Uploader -->
<virtualType name="VendorModuleModelImageUploader" type="VendorModuleModelImageUploader">
<arguments>
<argument name="baseTmpPath" xsi:type="string">test/tmp/image</argument>
<argument name="basePath" xsi:type="string">test/image</argument>
<argument name="allowedExtensions" xsi:type="array">
<item name="jpg" xsi:type="string">jpg</item>
<item name="jpeg" xsi:type="string">jpeg</item>
<item name="gif" xsi:type="string">gif</item>
<item name="png" xsi:type="string">png</item>
</argument>
</arguments>
</virtualType>
<type name="VendorModuleControllerAdminhtmlTestUpload">
<arguments>
<argument name="imageUploader" xsi:type="object">VendorModuleModelImageUploader</argument>
</arguments>
</type>
<!-- End Image Uploader -->


ImageUploader.php :



<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace VendorModuleModel;

/**
* Catalog image uploader
*/
class ImageUploader
/**
* Core file storage database
*
* @var MagentoMediaStorageHelperFileStorageDatabase
*/
protected $coreFileStorageDatabase;

/**
* Media directory object (writable).
*
* @var MagentoFrameworkFilesystemDirectoryWriteInterface
*/
protected $mediaDirectory;

/**
* Uploader factory
*
* @var MagentoMediaStorageModelFileUploaderFactory
*/
private $uploaderFactory;

/**
* Store manager
*
* @var MagentoStoreModelStoreManagerInterface
*/
protected $storeManager;

/**
* @var PsrLogLoggerInterface
*/
protected $logger;

/**
* Base tmp path
*
* @var string
*/
protected $baseTmpPath;

/**
* Base path
*
* @var string
*/
protected $basePath;

/**
* Allowed extensions
*
* @var string
*/
protected $allowedExtensions;

/**
* ImageUploader constructor
*
* @param MagentoMediaStorageHelperFileStorageDatabase $coreFileStorageDatabase
* @param MagentoFrameworkFilesystem $filesystem
* @param MagentoMediaStorageModelFileUploaderFactory $uploaderFactory
* @param MagentoStoreModelStoreManagerInterface $storeManager
* @param PsrLogLoggerInterface $logger
* @param string $baseTmpPath
* @param string $basePath
* @param string[] $allowedExtensions
*/
public function __construct(
MagentoMediaStorageHelperFileStorageDatabase $coreFileStorageDatabase,
MagentoFrameworkFilesystem $filesystem,
MagentoMediaStorageModelFileUploaderFactory $uploaderFactory,
MagentoStoreModelStoreManagerInterface $storeManager,
PsrLogLoggerInterface $logger,
$baseTmpPath,
$basePath,
$allowedExtensions
)
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
$this->mediaDirectory = $filesystem->getDirectoryWrite(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
$this->uploaderFactory = $uploaderFactory;
$this->storeManager = $storeManager;
$this->logger = $logger;
$this->baseTmpPath = $baseTmpPath;
$this->basePath = $basePath;
$this->allowedExtensions = $allowedExtensions;


/**
* Set base tmp path
*
* @param string $baseTmpPath
*
* @return void
*/
public function setBaseTmpPath($baseTmpPath)
$this->baseTmpPath = $baseTmpPath;


/**
* Set base path
*
* @param string $basePath
*
* @return void
*/
public function setBasePath($basePath)
$this->basePath = $basePath;


/**
* Set allowed extensions
*
* @param string[] $allowedExtensions
*
* @return void
*/
public function setAllowedExtensions($allowedExtensions)
$this->allowedExtensions = $allowedExtensions;


/**
* Retrieve base tmp path
*
* @return string
*/
public function getBaseTmpPath()
return $this->baseTmpPath;


/**
* Retrieve base path
*
* @return string
*/
public function getBasePath()
return $this->basePath;


/**
* Retrieve base path
*
* @return string[]
*/
public function getAllowedExtensions()
return $this->allowedExtensions;


/**
* Retrieve path
*
* @param string $path
* @param string $imageName
*
* @return string
*/
public function getFilePath($path, $imageName)
return rtrim($path, '/') . '/' . ltrim($imageName, '/');


/**
* Checking file for moving and move it
*
* @param string $imageName
*
* @return string
*
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function moveFileFromTmp($imageName)
$baseTmpPath = $this->getBaseTmpPath();
$basePath = $this->getBasePath();

$baseImagePath = $this->getFilePath($basePath, $imageName);
$baseTmpImagePath = $this->getFilePath($baseTmpPath, $imageName);

try
$this->coreFileStorageDatabase->copyFile(
$baseTmpImagePath,
$baseImagePath
);
$this->mediaDirectory->renameFile($baseTmpImagePath, $baseImagePath);
catch (Exception $e)
throw new MagentoFrameworkExceptionLocalizedException(
__('Something went wrong while saving the file(s).')
);


return $imageName;


/**
* Checking file for save and save it to tmp dir
*
* @param string $fileId
*
* @return string[]
*
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function saveFileToTmpDir($fileId)
$baseTmpPath = $this->getBaseTmpPath();
$uploader = $this->uploaderFactory->create(['fileId' => $fileId]);
$uploader->setAllowedExtensions($this->getAllowedExtensions());
$uploader->setAllowRenameFiles(true);

$result = $uploader->save($this->mediaDirectory->getAbsolutePath($baseTmpPath));

if (!$result)
throw new MagentoFrameworkExceptionLocalizedException(
__('File can not be saved to the destination folder.')
);


$result['tmp_name'] = str_replace('\', '/', $result['tmp_name']);
$result['path'] = str_replace('\', '/', $result['path']);
$result['url'] = $this->storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . $this->getFilePath($baseTmpPath, $result['file']);
$result['name'] = $result['file'];

if (isset($result['file']))
try
$relativePath = rtrim($baseTmpPath, '/') . '/' . ltrim($result['file'], '/');
$this->coreFileStorageDatabase->saveFile($relativePath);
catch (Exception $e)
$this->logger->critical($e);
throw new MagentoFrameworkExceptionLocalizedException(
__('Something went wrong while saving the file(s).')
);



return $result;




Save.php :



private function imageSaveToDir(array $rawData) 
$data = $rawData;
if (isset($data['review_image'][0]['name']) && isset($data['review_image'][0]['tmp_name']))
$data['review_image'] = $data['review_image'][0]['name'];
/** VendorModuleModelImageUploader $imageUploader*/
$this->imageUploader->moveFileFromTmp($data['review_image']);
elseif (isset($data['review_image'][0]['image']) && !isset($data['review_image'][0]['tmp_name']))
$data['review_image'] = $data['review_image'][0]['image'];
else
$data['review_image'] = null;

return $data;



DataProvider.php :



if (!$this->loadedData) 
$storeId = (int) $this->request->getParam('store');
$this->collection->setStoreId($storeId)->addAttributeToSelect('*');
$items = $this->collection->getItems();
foreach ($items as $item)
$itemData = $item->getData();
$imageName = $itemData['review_image'];
$itemData['review_image'] = array(
[
'name' => $imageName,
'url' => $this->storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'test/image/' . $imageName,
],
);
$item->setStoreId($storeId);
$this->loadedData[$item->getEntityId()] = $itemData;
break;




Upload.php :



public function execute() 
$imageUploadId = $this->_request->getParam('param_name', 'review_image');
try
$this->imageUploader->setBaseTmpPath('test/tmp/image');
$this->imageUploader->setBasePath('test/image');
$imageResult = $this->imageUploader->saveFileToTmpDir($imageUploadId);

$imageResult['cookie'] = [
'name' => $this->_getSession()->getName(),
'value' => $this->_getSession()->getSessionId(),
'lifetime' => $this->_getSession()->getCookieLifetime(),
'path' => $this->_getSession()->getCookiePath(),
'domain' => $this->_getSession()->getCookieDomain(),
];
catch (Exception $e)
$imageResult = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];

return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($imageResult);



What I missing here ?



Please help me.



Thanks.










share|improve this question
















I used image uploader in ui form. But, when I save image not saved in main folder and return error




Missing required argument $baseTmpPath of VendorModuleModelImageUploader.




My Files code :



di.xml :



<!-- Image Uploader -->
<virtualType name="VendorModuleModelImageUploader" type="VendorModuleModelImageUploader">
<arguments>
<argument name="baseTmpPath" xsi:type="string">test/tmp/image</argument>
<argument name="basePath" xsi:type="string">test/image</argument>
<argument name="allowedExtensions" xsi:type="array">
<item name="jpg" xsi:type="string">jpg</item>
<item name="jpeg" xsi:type="string">jpeg</item>
<item name="gif" xsi:type="string">gif</item>
<item name="png" xsi:type="string">png</item>
</argument>
</arguments>
</virtualType>
<type name="VendorModuleControllerAdminhtmlTestUpload">
<arguments>
<argument name="imageUploader" xsi:type="object">VendorModuleModelImageUploader</argument>
</arguments>
</type>
<!-- End Image Uploader -->


ImageUploader.php :



<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace VendorModuleModel;

/**
* Catalog image uploader
*/
class ImageUploader
/**
* Core file storage database
*
* @var MagentoMediaStorageHelperFileStorageDatabase
*/
protected $coreFileStorageDatabase;

/**
* Media directory object (writable).
*
* @var MagentoFrameworkFilesystemDirectoryWriteInterface
*/
protected $mediaDirectory;

/**
* Uploader factory
*
* @var MagentoMediaStorageModelFileUploaderFactory
*/
private $uploaderFactory;

/**
* Store manager
*
* @var MagentoStoreModelStoreManagerInterface
*/
protected $storeManager;

/**
* @var PsrLogLoggerInterface
*/
protected $logger;

/**
* Base tmp path
*
* @var string
*/
protected $baseTmpPath;

/**
* Base path
*
* @var string
*/
protected $basePath;

/**
* Allowed extensions
*
* @var string
*/
protected $allowedExtensions;

/**
* ImageUploader constructor
*
* @param MagentoMediaStorageHelperFileStorageDatabase $coreFileStorageDatabase
* @param MagentoFrameworkFilesystem $filesystem
* @param MagentoMediaStorageModelFileUploaderFactory $uploaderFactory
* @param MagentoStoreModelStoreManagerInterface $storeManager
* @param PsrLogLoggerInterface $logger
* @param string $baseTmpPath
* @param string $basePath
* @param string[] $allowedExtensions
*/
public function __construct(
MagentoMediaStorageHelperFileStorageDatabase $coreFileStorageDatabase,
MagentoFrameworkFilesystem $filesystem,
MagentoMediaStorageModelFileUploaderFactory $uploaderFactory,
MagentoStoreModelStoreManagerInterface $storeManager,
PsrLogLoggerInterface $logger,
$baseTmpPath,
$basePath,
$allowedExtensions
)
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
$this->mediaDirectory = $filesystem->getDirectoryWrite(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
$this->uploaderFactory = $uploaderFactory;
$this->storeManager = $storeManager;
$this->logger = $logger;
$this->baseTmpPath = $baseTmpPath;
$this->basePath = $basePath;
$this->allowedExtensions = $allowedExtensions;


/**
* Set base tmp path
*
* @param string $baseTmpPath
*
* @return void
*/
public function setBaseTmpPath($baseTmpPath)
$this->baseTmpPath = $baseTmpPath;


/**
* Set base path
*
* @param string $basePath
*
* @return void
*/
public function setBasePath($basePath)
$this->basePath = $basePath;


/**
* Set allowed extensions
*
* @param string[] $allowedExtensions
*
* @return void
*/
public function setAllowedExtensions($allowedExtensions)
$this->allowedExtensions = $allowedExtensions;


/**
* Retrieve base tmp path
*
* @return string
*/
public function getBaseTmpPath()
return $this->baseTmpPath;


/**
* Retrieve base path
*
* @return string
*/
public function getBasePath()
return $this->basePath;


/**
* Retrieve base path
*
* @return string[]
*/
public function getAllowedExtensions()
return $this->allowedExtensions;


/**
* Retrieve path
*
* @param string $path
* @param string $imageName
*
* @return string
*/
public function getFilePath($path, $imageName)
return rtrim($path, '/') . '/' . ltrim($imageName, '/');


/**
* Checking file for moving and move it
*
* @param string $imageName
*
* @return string
*
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function moveFileFromTmp($imageName)
$baseTmpPath = $this->getBaseTmpPath();
$basePath = $this->getBasePath();

$baseImagePath = $this->getFilePath($basePath, $imageName);
$baseTmpImagePath = $this->getFilePath($baseTmpPath, $imageName);

try
$this->coreFileStorageDatabase->copyFile(
$baseTmpImagePath,
$baseImagePath
);
$this->mediaDirectory->renameFile($baseTmpImagePath, $baseImagePath);
catch (Exception $e)
throw new MagentoFrameworkExceptionLocalizedException(
__('Something went wrong while saving the file(s).')
);


return $imageName;


/**
* Checking file for save and save it to tmp dir
*
* @param string $fileId
*
* @return string[]
*
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function saveFileToTmpDir($fileId)
$baseTmpPath = $this->getBaseTmpPath();
$uploader = $this->uploaderFactory->create(['fileId' => $fileId]);
$uploader->setAllowedExtensions($this->getAllowedExtensions());
$uploader->setAllowRenameFiles(true);

$result = $uploader->save($this->mediaDirectory->getAbsolutePath($baseTmpPath));

if (!$result)
throw new MagentoFrameworkExceptionLocalizedException(
__('File can not be saved to the destination folder.')
);


$result['tmp_name'] = str_replace('\', '/', $result['tmp_name']);
$result['path'] = str_replace('\', '/', $result['path']);
$result['url'] = $this->storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . $this->getFilePath($baseTmpPath, $result['file']);
$result['name'] = $result['file'];

if (isset($result['file']))
try
$relativePath = rtrim($baseTmpPath, '/') . '/' . ltrim($result['file'], '/');
$this->coreFileStorageDatabase->saveFile($relativePath);
catch (Exception $e)
$this->logger->critical($e);
throw new MagentoFrameworkExceptionLocalizedException(
__('Something went wrong while saving the file(s).')
);



return $result;




Save.php :



private function imageSaveToDir(array $rawData) 
$data = $rawData;
if (isset($data['review_image'][0]['name']) && isset($data['review_image'][0]['tmp_name']))
$data['review_image'] = $data['review_image'][0]['name'];
/** VendorModuleModelImageUploader $imageUploader*/
$this->imageUploader->moveFileFromTmp($data['review_image']);
elseif (isset($data['review_image'][0]['image']) && !isset($data['review_image'][0]['tmp_name']))
$data['review_image'] = $data['review_image'][0]['image'];
else
$data['review_image'] = null;

return $data;



DataProvider.php :



if (!$this->loadedData) 
$storeId = (int) $this->request->getParam('store');
$this->collection->setStoreId($storeId)->addAttributeToSelect('*');
$items = $this->collection->getItems();
foreach ($items as $item)
$itemData = $item->getData();
$imageName = $itemData['review_image'];
$itemData['review_image'] = array(
[
'name' => $imageName,
'url' => $this->storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'test/image/' . $imageName,
],
);
$item->setStoreId($storeId);
$this->loadedData[$item->getEntityId()] = $itemData;
break;




Upload.php :



public function execute() 
$imageUploadId = $this->_request->getParam('param_name', 'review_image');
try
$this->imageUploader->setBaseTmpPath('test/tmp/image');
$this->imageUploader->setBasePath('test/image');
$imageResult = $this->imageUploader->saveFileToTmpDir($imageUploadId);

$imageResult['cookie'] = [
'name' => $this->_getSession()->getName(),
'value' => $this->_getSession()->getSessionId(),
'lifetime' => $this->_getSession()->getCookieLifetime(),
'path' => $this->_getSession()->getCookiePath(),
'domain' => $this->_getSession()->getCookieDomain(),
];
catch (Exception $e)
$imageResult = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];

return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($imageResult);



What I missing here ?



Please help me.



Thanks.







magento2 image-upload






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 18 at 5:24







Emipro Technologies Pvt. Ltd.

















asked Mar 16 at 7:04









Emipro Technologies Pvt. Ltd.Emipro Technologies Pvt. Ltd.

2,7001927




2,7001927












  • add contruct method too

    – Sohel Rana
    Mar 16 at 9:17











  • Which file's ? @SohelRana

    – Emipro Technologies Pvt. Ltd.
    Mar 17 at 9:18

















  • add contruct method too

    – Sohel Rana
    Mar 16 at 9:17











  • Which file's ? @SohelRana

    – Emipro Technologies Pvt. Ltd.
    Mar 17 at 9:18
















add contruct method too

– Sohel Rana
Mar 16 at 9:17





add contruct method too

– Sohel Rana
Mar 16 at 9:17













Which file's ? @SohelRana

– Emipro Technologies Pvt. Ltd.
Mar 17 at 9:18





Which file's ? @SohelRana

– Emipro Technologies Pvt. Ltd.
Mar 17 at 9:18










0






active

oldest

votes












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266166%2fmagento-2-missing-required-argument-basetmppath%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266166%2fmagento-2-missing-required-argument-basetmppath%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?