Magento 2: Image not uploading in grid "Attention: File was not uploaded”Magento 2.1 image not uploading in edit formAttention The file was not uploadedProduct Collection Only Getting the Main Website Products not All Store ProductsHow can i rewrite TierPrice Block in Magento2main.CRITICAL: Plugin class doesn't existWhy Getting categories and names on product view page Magento 2 fails?Magento 2.1 UI Component Image upload formMagento 2| How to get full billing address of orders?Magento 2.3 Can't view module's front end page output?magento 2.2 trying to save multi select value in databaseMagento 2: Image not uploading in UI form "Attention: File was not uploaded”How to create custom form in Magento 2.2.3Magento 2.3 email attachment not working while sending custom email

Inset Square From a Rectangular Face

Is recepted a word?

Have made several mistakes during the course of my PhD. Can't help but feel resentment. Can I get some advice about how to move forward?

Control GPIO pins from C

From France west coast to Portugal via ship?

Earliest evidence of objects intended for future archaeologists?

How to detect a failed AES256 decryption programmatically?

How could Tony Stark wield the Infinity Nano Gauntlet - at all?

Unsolved Problems due to Lack of Computational Power

Uploaded homemade mp3 to icloud music library, now "not available in my country or region"

Why did St. Jerome use "virago" in Gen. 2:23?

Do predators tend to have vertical slit pupils versus horizontal for prey animals?

Is there a way to make the "o" keypress of other-window <C-x><C-o> repeatable?

Can the front glass be repaired of a broken lens?

Check disk usage of files returned with spaces

Quick destruction of a helium filled airship?

Gofer work in exchange for Letter of Recommendation

Are unaudited server logs admissible in a court of law?

When does The Truman Show take place?

Are there reliable, formulaic ways to form chords on the guitar?

Show two plots together: a two dimensional curve tangent to the maxima of a three dimensional plot

Does git delete empty folders?

Can I check a small array of bools in one go?

Angles between vectors of center of two incircles



Magento 2: Image not uploading in grid "Attention: File was not uploaded”


Magento 2.1 image not uploading in edit formAttention The file was not uploadedProduct Collection Only Getting the Main Website Products not All Store ProductsHow can i rewrite TierPrice Block in Magento2main.CRITICAL: Plugin class doesn't existWhy Getting categories and names on product view page Magento 2 fails?Magento 2.1 UI Component Image upload formMagento 2| How to get full billing address of orders?Magento 2.3 Can't view module's front end page output?magento 2.2 trying to save multi select value in databaseMagento 2: Image not uploading in UI form "Attention: File was not uploaded”How to create custom form in Magento 2.2.3Magento 2.3 email attachment not working while sending custom email






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








1















Created a custom module using Ui_Component,facing problem during image upload.



Error (On alert) :




Attention: File was not uploaded




Ui_Component Form Code for Upload:



 <field name="icon">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">string</item>
<item name="source" xsi:type="string">Item</item>
<item name="label" xsi:type="string" translate="true">Group Image</item>
<item name="visible" xsi:type="boolean">true</item>
<item name="formElement" xsi:type="string">fileUploader</item>
<item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
<item name="previewTmpl" xsi:type="string">Testing_Test/image-preview</item>
<item name="required" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="number">40</item>
<item name="uploaderConfig" xsi:type="array">
<item name="url" xsi:type="url" path="testing/item/upload"/>
</item>
</item>
</argument>
</field>


image-preview.html (Path: Testing/Test/view/adminhtml/web/template)



<div class="file-uploader-summary">
<div class="file-uploader-preview">
<a attr="href: $parent.getFilePreview($file)" target="_blank">
<img
class="preview-image"
tabindex="0"
event="load: $parent.onPreviewLoad.bind($parent)"
attr="
src: $parent.getFilePreview($file),
alt: $file.name">
</a>

<div class="actions">
<button
type="button"
class="action-remove"
data-role="delete-button"
attr="title: $t('Delete image')"
click="$parent.removeFile.bind($parent, $file)">
<span translate="'Delete image'"/>
</button>
</div>
</div>

<div class="file-uploader-filename" text="$file.name"/>
<div class="file-uploader-meta">
<text args="$file.previewWidth"/>x<text args="$file.previewHeight"/>
</div>
</div>


Upload.php (Path: Testing/Test/Controller/Adminhtml/Item)



<?php
namespace TestingTestControllerAdminhtmlItem;

use MagentoFrameworkControllerResultFactory;


class Upload extends MagentoBackendAppAction

public $imageUploader;



public function __construct(
MagentoBackendAppActionContext $context,
VendorModuleModelImageUploader $imageUploader
)
parent::__construct($context);
$this->imageUploader = $imageUploader;


public function execute()

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

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





ImageUploader.php (Path: TestingTestModel)



namespace TestingTestModel;

class ImageUploader

private $coreFileStorageDatabase;
private $mediaDirectory;
private $uploaderFactory;
private $storeManager;
private $logger;
public $baseTmpPath;
public $basePath;
public $allowedExtensions;

public function __construct(
MagentoMediaStorageHelperFileStorageDatabase $coreFileStorageDatabase,
MagentoFrameworkFilesystem $filesystem,
MagentoMediaStorageModelFileUploaderFactory $uploaderFactory,
MagentoStoreModelStoreManagerInterface $storeManager,
PsrLogLoggerInterface $logger
)
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
$this->mediaDirectory = $filesystem->getDirectoryWrite(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
$this->uploaderFactory = $uploaderFactory;
$this->storeManager = $storeManager;
$this->logger = $logger;
$this->baseTmpPath = "item/tmp/icon";
$this->basePath = "item/icon";
$this->allowedExtensions= ['jpg', 'jpeg', 'gif', 'png'];


public function setBaseTmpPath($baseTmpPath)

$this->baseTmpPath = $baseTmpPath;


public function setBasePath($basePath)

$this->basePath = $basePath;


public function setAllowedExtensions($allowedExtensions)

$this->allowedExtensions = $allowedExtensions;


public function getBaseTmpPath()

return $this->baseTmpPath;


public function getBasePath()

return $this->basePath;


public function getAllowedExtensions()

return $this->allowedExtensions;


public function getFilePath($path, $imageName)

return rtrim($path, '/') . '/' . ltrim($imageName, '/');


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;


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;




di.xml



<type name="TestingTestModelImageUploader">
<arguments>

<argument name="baseTmpPath" xsi:type="string">item/tmp/icon</argument>
<argument name="basePath" xsi:type="string">item/icon</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>
</type>


Done with all this:




php bin/magento setup:upgrade



php bin/magento setup:di:compile php



bin/magento setup:static-content:deploy




Anything missing in this code ?










share|improve this question


























  • 500 Internal Server Error should leave the message with concrete error in webserver logs... what's that error?

    – Raul Sanchez
    Jan 2 at 14:20











  • 500 internal server fixed,but during upload getting alert as " Attention: File was not uploaded”

    – Rahul Singh
    Jan 4 at 8:49











  • magento.stackexchange.com/questions/186331/…

    – Raul Sanchez
    Jan 4 at 8:53











  • i tried those tricks, but not worked :(

    – Rahul Singh
    Jan 4 at 8:55











  • after debugging more, i found that $uploader = $this->uploaderFactory->create(['fileId' => $fileId]); is giving error. here uploderFactory create not working

    – Rahul Singh
    Jan 4 at 13:29

















1















Created a custom module using Ui_Component,facing problem during image upload.



Error (On alert) :




Attention: File was not uploaded




Ui_Component Form Code for Upload:



 <field name="icon">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">string</item>
<item name="source" xsi:type="string">Item</item>
<item name="label" xsi:type="string" translate="true">Group Image</item>
<item name="visible" xsi:type="boolean">true</item>
<item name="formElement" xsi:type="string">fileUploader</item>
<item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
<item name="previewTmpl" xsi:type="string">Testing_Test/image-preview</item>
<item name="required" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="number">40</item>
<item name="uploaderConfig" xsi:type="array">
<item name="url" xsi:type="url" path="testing/item/upload"/>
</item>
</item>
</argument>
</field>


image-preview.html (Path: Testing/Test/view/adminhtml/web/template)



<div class="file-uploader-summary">
<div class="file-uploader-preview">
<a attr="href: $parent.getFilePreview($file)" target="_blank">
<img
class="preview-image"
tabindex="0"
event="load: $parent.onPreviewLoad.bind($parent)"
attr="
src: $parent.getFilePreview($file),
alt: $file.name">
</a>

<div class="actions">
<button
type="button"
class="action-remove"
data-role="delete-button"
attr="title: $t('Delete image')"
click="$parent.removeFile.bind($parent, $file)">
<span translate="'Delete image'"/>
</button>
</div>
</div>

<div class="file-uploader-filename" text="$file.name"/>
<div class="file-uploader-meta">
<text args="$file.previewWidth"/>x<text args="$file.previewHeight"/>
</div>
</div>


Upload.php (Path: Testing/Test/Controller/Adminhtml/Item)



<?php
namespace TestingTestControllerAdminhtmlItem;

use MagentoFrameworkControllerResultFactory;


class Upload extends MagentoBackendAppAction

public $imageUploader;



public function __construct(
MagentoBackendAppActionContext $context,
VendorModuleModelImageUploader $imageUploader
)
parent::__construct($context);
$this->imageUploader = $imageUploader;


public function execute()

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

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





ImageUploader.php (Path: TestingTestModel)



namespace TestingTestModel;

class ImageUploader

private $coreFileStorageDatabase;
private $mediaDirectory;
private $uploaderFactory;
private $storeManager;
private $logger;
public $baseTmpPath;
public $basePath;
public $allowedExtensions;

public function __construct(
MagentoMediaStorageHelperFileStorageDatabase $coreFileStorageDatabase,
MagentoFrameworkFilesystem $filesystem,
MagentoMediaStorageModelFileUploaderFactory $uploaderFactory,
MagentoStoreModelStoreManagerInterface $storeManager,
PsrLogLoggerInterface $logger
)
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
$this->mediaDirectory = $filesystem->getDirectoryWrite(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
$this->uploaderFactory = $uploaderFactory;
$this->storeManager = $storeManager;
$this->logger = $logger;
$this->baseTmpPath = "item/tmp/icon";
$this->basePath = "item/icon";
$this->allowedExtensions= ['jpg', 'jpeg', 'gif', 'png'];


public function setBaseTmpPath($baseTmpPath)

$this->baseTmpPath = $baseTmpPath;


public function setBasePath($basePath)

$this->basePath = $basePath;


public function setAllowedExtensions($allowedExtensions)

$this->allowedExtensions = $allowedExtensions;


public function getBaseTmpPath()

return $this->baseTmpPath;


public function getBasePath()

return $this->basePath;


public function getAllowedExtensions()

return $this->allowedExtensions;


public function getFilePath($path, $imageName)

return rtrim($path, '/') . '/' . ltrim($imageName, '/');


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;


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;




di.xml



<type name="TestingTestModelImageUploader">
<arguments>

<argument name="baseTmpPath" xsi:type="string">item/tmp/icon</argument>
<argument name="basePath" xsi:type="string">item/icon</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>
</type>


Done with all this:




php bin/magento setup:upgrade



php bin/magento setup:di:compile php



bin/magento setup:static-content:deploy




Anything missing in this code ?










share|improve this question


























  • 500 Internal Server Error should leave the message with concrete error in webserver logs... what's that error?

    – Raul Sanchez
    Jan 2 at 14:20











  • 500 internal server fixed,but during upload getting alert as " Attention: File was not uploaded”

    – Rahul Singh
    Jan 4 at 8:49











  • magento.stackexchange.com/questions/186331/…

    – Raul Sanchez
    Jan 4 at 8:53











  • i tried those tricks, but not worked :(

    – Rahul Singh
    Jan 4 at 8:55











  • after debugging more, i found that $uploader = $this->uploaderFactory->create(['fileId' => $fileId]); is giving error. here uploderFactory create not working

    – Rahul Singh
    Jan 4 at 13:29













1












1








1








Created a custom module using Ui_Component,facing problem during image upload.



Error (On alert) :




Attention: File was not uploaded




Ui_Component Form Code for Upload:



 <field name="icon">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">string</item>
<item name="source" xsi:type="string">Item</item>
<item name="label" xsi:type="string" translate="true">Group Image</item>
<item name="visible" xsi:type="boolean">true</item>
<item name="formElement" xsi:type="string">fileUploader</item>
<item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
<item name="previewTmpl" xsi:type="string">Testing_Test/image-preview</item>
<item name="required" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="number">40</item>
<item name="uploaderConfig" xsi:type="array">
<item name="url" xsi:type="url" path="testing/item/upload"/>
</item>
</item>
</argument>
</field>


image-preview.html (Path: Testing/Test/view/adminhtml/web/template)



<div class="file-uploader-summary">
<div class="file-uploader-preview">
<a attr="href: $parent.getFilePreview($file)" target="_blank">
<img
class="preview-image"
tabindex="0"
event="load: $parent.onPreviewLoad.bind($parent)"
attr="
src: $parent.getFilePreview($file),
alt: $file.name">
</a>

<div class="actions">
<button
type="button"
class="action-remove"
data-role="delete-button"
attr="title: $t('Delete image')"
click="$parent.removeFile.bind($parent, $file)">
<span translate="'Delete image'"/>
</button>
</div>
</div>

<div class="file-uploader-filename" text="$file.name"/>
<div class="file-uploader-meta">
<text args="$file.previewWidth"/>x<text args="$file.previewHeight"/>
</div>
</div>


Upload.php (Path: Testing/Test/Controller/Adminhtml/Item)



<?php
namespace TestingTestControllerAdminhtmlItem;

use MagentoFrameworkControllerResultFactory;


class Upload extends MagentoBackendAppAction

public $imageUploader;



public function __construct(
MagentoBackendAppActionContext $context,
VendorModuleModelImageUploader $imageUploader
)
parent::__construct($context);
$this->imageUploader = $imageUploader;


public function execute()

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

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





ImageUploader.php (Path: TestingTestModel)



namespace TestingTestModel;

class ImageUploader

private $coreFileStorageDatabase;
private $mediaDirectory;
private $uploaderFactory;
private $storeManager;
private $logger;
public $baseTmpPath;
public $basePath;
public $allowedExtensions;

public function __construct(
MagentoMediaStorageHelperFileStorageDatabase $coreFileStorageDatabase,
MagentoFrameworkFilesystem $filesystem,
MagentoMediaStorageModelFileUploaderFactory $uploaderFactory,
MagentoStoreModelStoreManagerInterface $storeManager,
PsrLogLoggerInterface $logger
)
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
$this->mediaDirectory = $filesystem->getDirectoryWrite(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
$this->uploaderFactory = $uploaderFactory;
$this->storeManager = $storeManager;
$this->logger = $logger;
$this->baseTmpPath = "item/tmp/icon";
$this->basePath = "item/icon";
$this->allowedExtensions= ['jpg', 'jpeg', 'gif', 'png'];


public function setBaseTmpPath($baseTmpPath)

$this->baseTmpPath = $baseTmpPath;


public function setBasePath($basePath)

$this->basePath = $basePath;


public function setAllowedExtensions($allowedExtensions)

$this->allowedExtensions = $allowedExtensions;


public function getBaseTmpPath()

return $this->baseTmpPath;


public function getBasePath()

return $this->basePath;


public function getAllowedExtensions()

return $this->allowedExtensions;


public function getFilePath($path, $imageName)

return rtrim($path, '/') . '/' . ltrim($imageName, '/');


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;


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;




di.xml



<type name="TestingTestModelImageUploader">
<arguments>

<argument name="baseTmpPath" xsi:type="string">item/tmp/icon</argument>
<argument name="basePath" xsi:type="string">item/icon</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>
</type>


Done with all this:




php bin/magento setup:upgrade



php bin/magento setup:di:compile php



bin/magento setup:static-content:deploy




Anything missing in this code ?










share|improve this question
















Created a custom module using Ui_Component,facing problem during image upload.



Error (On alert) :




Attention: File was not uploaded




Ui_Component Form Code for Upload:



 <field name="icon">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="dataType" xsi:type="string">string</item>
<item name="source" xsi:type="string">Item</item>
<item name="label" xsi:type="string" translate="true">Group Image</item>
<item name="visible" xsi:type="boolean">true</item>
<item name="formElement" xsi:type="string">fileUploader</item>
<item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
<item name="previewTmpl" xsi:type="string">Testing_Test/image-preview</item>
<item name="required" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="number">40</item>
<item name="uploaderConfig" xsi:type="array">
<item name="url" xsi:type="url" path="testing/item/upload"/>
</item>
</item>
</argument>
</field>


image-preview.html (Path: Testing/Test/view/adminhtml/web/template)



<div class="file-uploader-summary">
<div class="file-uploader-preview">
<a attr="href: $parent.getFilePreview($file)" target="_blank">
<img
class="preview-image"
tabindex="0"
event="load: $parent.onPreviewLoad.bind($parent)"
attr="
src: $parent.getFilePreview($file),
alt: $file.name">
</a>

<div class="actions">
<button
type="button"
class="action-remove"
data-role="delete-button"
attr="title: $t('Delete image')"
click="$parent.removeFile.bind($parent, $file)">
<span translate="'Delete image'"/>
</button>
</div>
</div>

<div class="file-uploader-filename" text="$file.name"/>
<div class="file-uploader-meta">
<text args="$file.previewWidth"/>x<text args="$file.previewHeight"/>
</div>
</div>


Upload.php (Path: Testing/Test/Controller/Adminhtml/Item)



<?php
namespace TestingTestControllerAdminhtmlItem;

use MagentoFrameworkControllerResultFactory;


class Upload extends MagentoBackendAppAction

public $imageUploader;



public function __construct(
MagentoBackendAppActionContext $context,
VendorModuleModelImageUploader $imageUploader
)
parent::__construct($context);
$this->imageUploader = $imageUploader;


public function execute()

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

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





ImageUploader.php (Path: TestingTestModel)



namespace TestingTestModel;

class ImageUploader

private $coreFileStorageDatabase;
private $mediaDirectory;
private $uploaderFactory;
private $storeManager;
private $logger;
public $baseTmpPath;
public $basePath;
public $allowedExtensions;

public function __construct(
MagentoMediaStorageHelperFileStorageDatabase $coreFileStorageDatabase,
MagentoFrameworkFilesystem $filesystem,
MagentoMediaStorageModelFileUploaderFactory $uploaderFactory,
MagentoStoreModelStoreManagerInterface $storeManager,
PsrLogLoggerInterface $logger
)
$this->coreFileStorageDatabase = $coreFileStorageDatabase;
$this->mediaDirectory = $filesystem->getDirectoryWrite(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
$this->uploaderFactory = $uploaderFactory;
$this->storeManager = $storeManager;
$this->logger = $logger;
$this->baseTmpPath = "item/tmp/icon";
$this->basePath = "item/icon";
$this->allowedExtensions= ['jpg', 'jpeg', 'gif', 'png'];


public function setBaseTmpPath($baseTmpPath)

$this->baseTmpPath = $baseTmpPath;


public function setBasePath($basePath)

$this->basePath = $basePath;


public function setAllowedExtensions($allowedExtensions)

$this->allowedExtensions = $allowedExtensions;


public function getBaseTmpPath()

return $this->baseTmpPath;


public function getBasePath()

return $this->basePath;


public function getAllowedExtensions()

return $this->allowedExtensions;


public function getFilePath($path, $imageName)

return rtrim($path, '/') . '/' . ltrim($imageName, '/');


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;


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;




di.xml



<type name="TestingTestModelImageUploader">
<arguments>

<argument name="baseTmpPath" xsi:type="string">item/tmp/icon</argument>
<argument name="basePath" xsi:type="string">item/icon</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>
</type>


Done with all this:




php bin/magento setup:upgrade



php bin/magento setup:di:compile php



bin/magento setup:static-content:deploy




Anything missing in this code ?







magento2 uicomponent magento2.2.2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 8:50







Rahul Singh

















asked Jan 2 at 12:26









Rahul SinghRahul Singh

8621 gold badge10 silver badges26 bronze badges




8621 gold badge10 silver badges26 bronze badges















  • 500 Internal Server Error should leave the message with concrete error in webserver logs... what's that error?

    – Raul Sanchez
    Jan 2 at 14:20











  • 500 internal server fixed,but during upload getting alert as " Attention: File was not uploaded”

    – Rahul Singh
    Jan 4 at 8:49











  • magento.stackexchange.com/questions/186331/…

    – Raul Sanchez
    Jan 4 at 8:53











  • i tried those tricks, but not worked :(

    – Rahul Singh
    Jan 4 at 8:55











  • after debugging more, i found that $uploader = $this->uploaderFactory->create(['fileId' => $fileId]); is giving error. here uploderFactory create not working

    – Rahul Singh
    Jan 4 at 13:29

















  • 500 Internal Server Error should leave the message with concrete error in webserver logs... what's that error?

    – Raul Sanchez
    Jan 2 at 14:20











  • 500 internal server fixed,but during upload getting alert as " Attention: File was not uploaded”

    – Rahul Singh
    Jan 4 at 8:49











  • magento.stackexchange.com/questions/186331/…

    – Raul Sanchez
    Jan 4 at 8:53











  • i tried those tricks, but not worked :(

    – Rahul Singh
    Jan 4 at 8:55











  • after debugging more, i found that $uploader = $this->uploaderFactory->create(['fileId' => $fileId]); is giving error. here uploderFactory create not working

    – Rahul Singh
    Jan 4 at 13:29
















500 Internal Server Error should leave the message with concrete error in webserver logs... what's that error?

– Raul Sanchez
Jan 2 at 14:20





500 Internal Server Error should leave the message with concrete error in webserver logs... what's that error?

– Raul Sanchez
Jan 2 at 14:20













500 internal server fixed,but during upload getting alert as " Attention: File was not uploaded”

– Rahul Singh
Jan 4 at 8:49





500 internal server fixed,but during upload getting alert as " Attention: File was not uploaded”

– Rahul Singh
Jan 4 at 8:49













magento.stackexchange.com/questions/186331/…

– Raul Sanchez
Jan 4 at 8:53





magento.stackexchange.com/questions/186331/…

– Raul Sanchez
Jan 4 at 8:53













i tried those tricks, but not worked :(

– Rahul Singh
Jan 4 at 8:55





i tried those tricks, but not worked :(

– Rahul Singh
Jan 4 at 8:55













after debugging more, i found that $uploader = $this->uploaderFactory->create(['fileId' => $fileId]); is giving error. here uploderFactory create not working

– Rahul Singh
Jan 4 at 13:29





after debugging more, i found that $uploader = $this->uploaderFactory->create(['fileId' => $fileId]); is giving error. here uploderFactory create not working

– Rahul Singh
Jan 4 at 13:29










1 Answer
1






active

oldest

votes


















0














Looking your last comment, and giving a look to documentation, I am not sure why are you using Factory for that model



https://devdocs.magento.com/guides/v2.3/extension-dev-guide/factories.html




Factories are service classes that instantiate non-injectable classes, that is, models that represent a database entity . They create a layer of abstraction between the ObjectManager and business code.




So, I think you should use just MagentoMediaStorageModelFileUploader in TestingTestModelImageUploader constructor






share|improve this answer

























  • it gives error "A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later."

    – Rahul Singh
    Jan 7 at 4:29











  • I followed this for solution magento.stackexchange.com/questions/138642/… , but still not worked :(

    – Rahul Singh
    Jan 7 at 5:56











  • "A technical problem with the server created an error" message should leave concrete error in application / webserver logs... check that & paste the error

    – Raul Sanchez
    Jan 7 at 9:07











  • no error on logs too :(

    – Rahul Singh
    Jan 8 at 7:23












  • We are blind then

    – Raul Sanchez
    Jan 8 at 8:39













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%2f256455%2fmagento-2-image-not-uploading-in-grid-attention-file-was-not-uploaded%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Looking your last comment, and giving a look to documentation, I am not sure why are you using Factory for that model



https://devdocs.magento.com/guides/v2.3/extension-dev-guide/factories.html




Factories are service classes that instantiate non-injectable classes, that is, models that represent a database entity . They create a layer of abstraction between the ObjectManager and business code.




So, I think you should use just MagentoMediaStorageModelFileUploader in TestingTestModelImageUploader constructor






share|improve this answer

























  • it gives error "A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later."

    – Rahul Singh
    Jan 7 at 4:29











  • I followed this for solution magento.stackexchange.com/questions/138642/… , but still not worked :(

    – Rahul Singh
    Jan 7 at 5:56











  • "A technical problem with the server created an error" message should leave concrete error in application / webserver logs... check that & paste the error

    – Raul Sanchez
    Jan 7 at 9:07











  • no error on logs too :(

    – Rahul Singh
    Jan 8 at 7:23












  • We are blind then

    – Raul Sanchez
    Jan 8 at 8:39















0














Looking your last comment, and giving a look to documentation, I am not sure why are you using Factory for that model



https://devdocs.magento.com/guides/v2.3/extension-dev-guide/factories.html




Factories are service classes that instantiate non-injectable classes, that is, models that represent a database entity . They create a layer of abstraction between the ObjectManager and business code.




So, I think you should use just MagentoMediaStorageModelFileUploader in TestingTestModelImageUploader constructor






share|improve this answer

























  • it gives error "A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later."

    – Rahul Singh
    Jan 7 at 4:29











  • I followed this for solution magento.stackexchange.com/questions/138642/… , but still not worked :(

    – Rahul Singh
    Jan 7 at 5:56











  • "A technical problem with the server created an error" message should leave concrete error in application / webserver logs... check that & paste the error

    – Raul Sanchez
    Jan 7 at 9:07











  • no error on logs too :(

    – Rahul Singh
    Jan 8 at 7:23












  • We are blind then

    – Raul Sanchez
    Jan 8 at 8:39













0












0








0







Looking your last comment, and giving a look to documentation, I am not sure why are you using Factory for that model



https://devdocs.magento.com/guides/v2.3/extension-dev-guide/factories.html




Factories are service classes that instantiate non-injectable classes, that is, models that represent a database entity . They create a layer of abstraction between the ObjectManager and business code.




So, I think you should use just MagentoMediaStorageModelFileUploader in TestingTestModelImageUploader constructor






share|improve this answer













Looking your last comment, and giving a look to documentation, I am not sure why are you using Factory for that model



https://devdocs.magento.com/guides/v2.3/extension-dev-guide/factories.html




Factories are service classes that instantiate non-injectable classes, that is, models that represent a database entity . They create a layer of abstraction between the ObjectManager and business code.




So, I think you should use just MagentoMediaStorageModelFileUploader in TestingTestModelImageUploader constructor







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 4 at 14:11









Raul SanchezRaul Sanchez

2,1473 gold badges13 silver badges40 bronze badges




2,1473 gold badges13 silver badges40 bronze badges















  • it gives error "A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later."

    – Rahul Singh
    Jan 7 at 4:29











  • I followed this for solution magento.stackexchange.com/questions/138642/… , but still not worked :(

    – Rahul Singh
    Jan 7 at 5:56











  • "A technical problem with the server created an error" message should leave concrete error in application / webserver logs... check that & paste the error

    – Raul Sanchez
    Jan 7 at 9:07











  • no error on logs too :(

    – Rahul Singh
    Jan 8 at 7:23












  • We are blind then

    – Raul Sanchez
    Jan 8 at 8:39

















  • it gives error "A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later."

    – Rahul Singh
    Jan 7 at 4:29











  • I followed this for solution magento.stackexchange.com/questions/138642/… , but still not worked :(

    – Rahul Singh
    Jan 7 at 5:56











  • "A technical problem with the server created an error" message should leave concrete error in application / webserver logs... check that & paste the error

    – Raul Sanchez
    Jan 7 at 9:07











  • no error on logs too :(

    – Rahul Singh
    Jan 8 at 7:23












  • We are blind then

    – Raul Sanchez
    Jan 8 at 8:39
















it gives error "A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later."

– Rahul Singh
Jan 7 at 4:29





it gives error "A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later."

– Rahul Singh
Jan 7 at 4:29













I followed this for solution magento.stackexchange.com/questions/138642/… , but still not worked :(

– Rahul Singh
Jan 7 at 5:56





I followed this for solution magento.stackexchange.com/questions/138642/… , but still not worked :(

– Rahul Singh
Jan 7 at 5:56













"A technical problem with the server created an error" message should leave concrete error in application / webserver logs... check that & paste the error

– Raul Sanchez
Jan 7 at 9:07





"A technical problem with the server created an error" message should leave concrete error in application / webserver logs... check that & paste the error

– Raul Sanchez
Jan 7 at 9:07













no error on logs too :(

– Rahul Singh
Jan 8 at 7:23






no error on logs too :(

– Rahul Singh
Jan 8 at 7:23














We are blind then

– Raul Sanchez
Jan 8 at 8:39





We are blind then

– Raul Sanchez
Jan 8 at 8:39

















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%2f256455%2fmagento-2-image-not-uploading-in-grid-attention-file-was-not-uploaded%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?