Magento – Magento 2: Swatch image upload not working due to js error

configurable-swatchesmagento2magento2.1.6PHPswatches

I am working on magento 2 and when i try to upload a swatch attribute image but each time i get the below error. Please check the below screenshot.

enter image description here

I debug code more and found that image path error.

This is my js path : vendor/magento/module-swatches/view/adminhtml/web/js

iframeHandler = function () {
       var imageParams = $.parseJSON($(this).contents().find('body').html()),
       fullMediaUrl = imageParams['swatch_path'] + imageParams['file_path'];

imageParams['file_path'] value is undefined.

Please help me to resolve this error.

Best Answer

I have a solution for your issue.

It cause is the role of admin .. Please change ADMIN_RESOURCE from Magento_Swatches::iframe to Magento_Backend::admin in file Magento\Swatches\Controller\Adminhtml\Iframe\Show