Skip to content

image uploader does not work when more than one fieldset in admin UI Component Form in magneto 2

When we upload image with single fieldset it’s working fine but when 2 fieldset is coming in picture then its’ not working please check the error .
Warning: Undefined array key “supplier-info][upload_document” in /var/www/html/vendor/magento/framework/File/Uploader.php on line 701

Anyone tell me How to fix this?

 <fieldset name="supplier-information">
    <fieldset name="supplier-info">
      <field name="upload_document" formElement="imageUploader">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="dataType" xsi:type="string">string</item>
            <item name="label" xsi:type="string" translate="true">Product Label Image</item>
            <item name="visible" xsi:type="boolean">true</item>
            <item name="allowedExtensions" xsi:type="string">jpg jpeg gif png svg</item>
            <item name="maxFileSize" xsi:type="number">2097152</item>
            <item name="formElement" xsi:type="string">imageUploader</item>
            <item name="previewTmpl" xsi:type="string">Magento_Catalog/image-preview</item>
            <item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
            <item name="dataScope" xsi:type="string">upload_document</item>
            <item name="sortOrder" xsi:type="number">40</item>
            <item name="uploaderConfig" xsi:type="array">
                <item name="url" xsi:type="url" path="registrationform/index/upload"/>
            </item>
            <item name="validation" xsi:type="array">
                <item name="required-entry" xsi:type="boolean">false</item>
            </item>
        </item>
    </argument>
    </field>
   </fieldset>
</fieldset>

Controller:

<?php

namespace CreateRegistrationFormControllerAdminhtmlIndex;

use MagentoFrameworkControllerResultFactory;

class Upload extends MagentoBackendAppAction
{

    /**
      @var VendornameHelloworldModelImageUploader
     /
    public $imageUploader;

    
    public function construct(
        MagentoBackendAppActionContext $context,
        CreateRegistrationFormModelImageUploader $imageUploader
    ) {
        parent::construct($context);
        $this->imageUploader = $imageUploader;
    }

    /**
      @return mixed
     /
    public function isAllowed() {
        return $this->authorization->isAllowed('Create_RegistrationForm::upload');
    }

    /**
      @return mixed
     /
    public function execute() {
        try {
            $imageUploadId = $this->getRequest()->getParam('param_name', 'upload_document');

            $result = $this->imageUploader->saveFileToTmpDir($imageUploadId);

            $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);
    }
}