Magento 2.2: Weird $_files array after image uploadMissing image upload buttonHow can i rewrite TierPrice Block in Magento2Not Saving image correctly - $_FILES OR $_GETHow to add an image uploader (to record an image and its path in the Magento store config) to the admin form, using .xml files?Upload File Magento 2AbstractFieldArray with Image UploadMagento image size increase after uploadImage upload and Preview on productImage upload resulting in empty $_FILES array in magento 2Image Uploader throws Uncaught type Error in Ui Component

Why favour the standard WP loop over iterating over (new WP_Query())->get_posts()?

How can I prevent Bash expansion from passing files starting with "-" as argument?

How to safely discharge oneself

How do I unravel apparent recursion in an edef statement?

Very serious stuff - Salesforce bug enabled "Modify All"

Addressing an email

Is there any official Lore on Keraptis the Wizard, apart from what is in White Plume Mountain?

How does the "reverse syntax" in Middle English work?

In how many ways can we partition a set into smaller subsets so the sum of the numbers in each subset is equal?

How could Dwarves prevent sand from filling up their settlements

If you attack a Tarrasque while swallowed, what AC do you need to beat to hit it?

How do we explain the use of a software on a math paper?

Is my company merging branches wrong?

Bash Array of Word-Splitting Headaches

Does the Aboleth have expertise in history and perception?

pwaS eht tirsf dna tasl setterl fo hace dorw

Why are Marine Le Pen's possible connections with Steve Bannon something worth investigating?

Who is frowning in the sentence "Daisy looked at Tom frowning"?

Would it be possible to set up a franchise in the ancient world?

Have I found a major security issue with login

Does a windmilling propeller create more drag than a stopped propeller in an engine out scenario?

Greek theta instead of lower case þ (Icelandic) in TexStudio

Why can I not put the limit inside the limit definition of e?

What's is the easiest way to purchase a stock and hold it



Magento 2.2: Weird $_files array after image upload


Missing image upload buttonHow can i rewrite TierPrice Block in Magento2Not Saving image correctly - $_FILES OR $_GETHow to add an image uploader (to record an image and its path in the Magento store config) to the admin form, using .xml files?Upload File Magento 2AbstractFieldArray with Image UploadMagento image size increase after uploadImage upload and Preview on productImage upload resulting in empty $_FILES array in magento 2Image Uploader throws Uncaught type Error in Ui Component






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








1















currently I'm trying to develop an image upload in the Magento admin area with ui components. My fieldset declarations looks like this:



<fieldset name="slide">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Slide Konfiguration</item>
</item>
</argument>

<!-- other fields -->

<field name="image">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
<item name="required" xsi:type="boolean">true</item>
<item name="label" xsi:type="string">Bild*</item>
<item name="visible" xsi:type="boolean">true</item>
<item name="formElement" xsi:type="string">fileUploader</item>
<item name="uploaderConfig" xsi:type="array">
<item name="url" xsi:type="url" path="cssslider/configuration/upload"/>
</item>
</item>
</argument>
</field>
</fieldset>


My upload action contains this line



$result = $this->imageUploader->upload('slide');


If I stop code here with a breakpoint and inspect the $_files array, it looks like this:
enter image description here



Every item in the slides array contains another array?! (Whyyy?!!) And because of this my code throws an exception in the MagentoFrameworkFileUploader class in line 162 where it checks, if the file already exists:



if (!file_exists($this->_file['tmp_name'])) {


$this->_file contains the slide-array of the $_files array.



Anybody got an idea what I need to do to fix this issue?










share|improve this question




























    1















    currently I'm trying to develop an image upload in the Magento admin area with ui components. My fieldset declarations looks like this:



    <fieldset name="slide">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="label" xsi:type="string" translate="true">Slide Konfiguration</item>
    </item>
    </argument>

    <!-- other fields -->

    <field name="image">
    <argument name="data" xsi:type="array">
    <item name="config" xsi:type="array">
    <item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
    <item name="required" xsi:type="boolean">true</item>
    <item name="label" xsi:type="string">Bild*</item>
    <item name="visible" xsi:type="boolean">true</item>
    <item name="formElement" xsi:type="string">fileUploader</item>
    <item name="uploaderConfig" xsi:type="array">
    <item name="url" xsi:type="url" path="cssslider/configuration/upload"/>
    </item>
    </item>
    </argument>
    </field>
    </fieldset>


    My upload action contains this line



    $result = $this->imageUploader->upload('slide');


    If I stop code here with a breakpoint and inspect the $_files array, it looks like this:
    enter image description here



    Every item in the slides array contains another array?! (Whyyy?!!) And because of this my code throws an exception in the MagentoFrameworkFileUploader class in line 162 where it checks, if the file already exists:



    if (!file_exists($this->_file['tmp_name'])) {


    $this->_file contains the slide-array of the $_files array.



    Anybody got an idea what I need to do to fix this issue?










    share|improve this question
























      1












      1








      1








      currently I'm trying to develop an image upload in the Magento admin area with ui components. My fieldset declarations looks like this:



      <fieldset name="slide">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="label" xsi:type="string" translate="true">Slide Konfiguration</item>
      </item>
      </argument>

      <!-- other fields -->

      <field name="image">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
      <item name="required" xsi:type="boolean">true</item>
      <item name="label" xsi:type="string">Bild*</item>
      <item name="visible" xsi:type="boolean">true</item>
      <item name="formElement" xsi:type="string">fileUploader</item>
      <item name="uploaderConfig" xsi:type="array">
      <item name="url" xsi:type="url" path="cssslider/configuration/upload"/>
      </item>
      </item>
      </argument>
      </field>
      </fieldset>


      My upload action contains this line



      $result = $this->imageUploader->upload('slide');


      If I stop code here with a breakpoint and inspect the $_files array, it looks like this:
      enter image description here



      Every item in the slides array contains another array?! (Whyyy?!!) And because of this my code throws an exception in the MagentoFrameworkFileUploader class in line 162 where it checks, if the file already exists:



      if (!file_exists($this->_file['tmp_name'])) {


      $this->_file contains the slide-array of the $_files array.



      Anybody got an idea what I need to do to fix this issue?










      share|improve this question














      currently I'm trying to develop an image upload in the Magento admin area with ui components. My fieldset declarations looks like this:



      <fieldset name="slide">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="label" xsi:type="string" translate="true">Slide Konfiguration</item>
      </item>
      </argument>

      <!-- other fields -->

      <field name="image">
      <argument name="data" xsi:type="array">
      <item name="config" xsi:type="array">
      <item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
      <item name="required" xsi:type="boolean">true</item>
      <item name="label" xsi:type="string">Bild*</item>
      <item name="visible" xsi:type="boolean">true</item>
      <item name="formElement" xsi:type="string">fileUploader</item>
      <item name="uploaderConfig" xsi:type="array">
      <item name="url" xsi:type="url" path="cssslider/configuration/upload"/>
      </item>
      </item>
      </argument>
      </field>
      </fieldset>


      My upload action contains this line



      $result = $this->imageUploader->upload('slide');


      If I stop code here with a breakpoint and inspect the $_files array, it looks like this:
      enter image description here



      Every item in the slides array contains another array?! (Whyyy?!!) And because of this my code throws an exception in the MagentoFrameworkFileUploader class in line 162 where it checks, if the file already exists:



      if (!file_exists($this->_file['tmp_name'])) {


      $this->_file contains the slide-array of the $_files array.



      Anybody got an idea what I need to do to fix this issue?







      magento2 php image-upload file-upload array






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 26 '18 at 14:54









      jennymojennymo

      1064




      1064




















          5 Answers
          5






          active

          oldest

          votes


















          4





          +25









          Didn't test this, but I think



          $result = $this->imageUploader->upload('slide'); 


          should be



          $result = $this->imageUploader->upload('image'); //use the name of the field not of the fieldset. 


          Also add this inside the <item name="config" xsi:type="array"> element



          <item name="dataScope" xsi:type="string">image</item>





          share|improve this answer






























            0














            Change the uploaderConfig to:



             <item name="uploaderConfig" xsi:type="array">
            <item name="url" xsi:type="string">cssslider/configuration/upload</item>
            </item>





            share|improve this answer























            • Unfortunately no change. Still the same error with this code.

              – jennymo
              Mar 27 '18 at 7:18


















            0














            You could use my code from here https://github.com/konarshankar07/magento2-cms-hero-image.
            It will help you to fix your issue. Can you please add more code like di.xml code and upload.php code? It might be easy for me to fix this issue



            Thanks






            share|improve this answer






























              0














              You could try my personal code for the image uploader on Ui component



               <field name="banner_image">
              <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">template</item>
              <item name="label" xsi:type="string" translate="true">Banner 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">Vendor_Module/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="vendor_module/template_banner/upload"/>
              </item>
              </item>
              </argument>
              </field>


              app/code/Vendor/Module/view/adminhtml/web/template/image-preview.html



              <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>


              From Save controller



              $data = $this->getRequest()->getPostValue();
              $data = $this->_filterPostData($data);
              $model->setData($data)->save();


              Add another filter for image uploader to avoid error before save



              /**
              * Filter template data.
              *
              * @param array $rawData
              * @return array
              */
              protected function _filterPostData(array $rawData)

              $data = $rawData;
              // @todo It is a workaround to prevent saving this data in category model and it has to be refactored in future
              if (isset($data['banner_image']) && is_array($data['banner_image']))
              if (!empty($data['banner_image']['delete']))
              $data['banner_image'] = null;
              else
              if (isset($data['banner_image'][0]['name']) && isset($data['banner_image'][0]['tmp_name']))
              $data['banner_image'] = $data['banner_image'][0]['name'];
              else
              unset($data['banner_image']);



              return $data;






              share|improve this answer






























                0














                I add the same issue.



                Your upload action should be like this :



                $result = $this->imageUploader->upload('slide[image]');






                share|improve this answer























                  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%2f219907%2fmagento-2-2-weird-files-array-after-image-upload%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown

























                  5 Answers
                  5






                  active

                  oldest

                  votes








                  5 Answers
                  5






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  4





                  +25









                  Didn't test this, but I think



                  $result = $this->imageUploader->upload('slide'); 


                  should be



                  $result = $this->imageUploader->upload('image'); //use the name of the field not of the fieldset. 


                  Also add this inside the <item name="config" xsi:type="array"> element



                  <item name="dataScope" xsi:type="string">image</item>





                  share|improve this answer



























                    4





                    +25









                    Didn't test this, but I think



                    $result = $this->imageUploader->upload('slide'); 


                    should be



                    $result = $this->imageUploader->upload('image'); //use the name of the field not of the fieldset. 


                    Also add this inside the <item name="config" xsi:type="array"> element



                    <item name="dataScope" xsi:type="string">image</item>





                    share|improve this answer

























                      4





                      +25







                      4





                      +25



                      4




                      +25





                      Didn't test this, but I think



                      $result = $this->imageUploader->upload('slide'); 


                      should be



                      $result = $this->imageUploader->upload('image'); //use the name of the field not of the fieldset. 


                      Also add this inside the <item name="config" xsi:type="array"> element



                      <item name="dataScope" xsi:type="string">image</item>





                      share|improve this answer













                      Didn't test this, but I think



                      $result = $this->imageUploader->upload('slide'); 


                      should be



                      $result = $this->imageUploader->upload('image'); //use the name of the field not of the fieldset. 


                      Also add this inside the <item name="config" xsi:type="array"> element



                      <item name="dataScope" xsi:type="string">image</item>






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jan 14 at 13:53









                      MariusMarius

                      169k28326696




                      169k28326696























                          0














                          Change the uploaderConfig to:



                           <item name="uploaderConfig" xsi:type="array">
                          <item name="url" xsi:type="string">cssslider/configuration/upload</item>
                          </item>





                          share|improve this answer























                          • Unfortunately no change. Still the same error with this code.

                            – jennymo
                            Mar 27 '18 at 7:18















                          0














                          Change the uploaderConfig to:



                           <item name="uploaderConfig" xsi:type="array">
                          <item name="url" xsi:type="string">cssslider/configuration/upload</item>
                          </item>





                          share|improve this answer























                          • Unfortunately no change. Still the same error with this code.

                            – jennymo
                            Mar 27 '18 at 7:18













                          0












                          0








                          0







                          Change the uploaderConfig to:



                           <item name="uploaderConfig" xsi:type="array">
                          <item name="url" xsi:type="string">cssslider/configuration/upload</item>
                          </item>





                          share|improve this answer













                          Change the uploaderConfig to:



                           <item name="uploaderConfig" xsi:type="array">
                          <item name="url" xsi:type="string">cssslider/configuration/upload</item>
                          </item>






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 26 '18 at 15:10









                          MehdiMehdi

                          609721




                          609721












                          • Unfortunately no change. Still the same error with this code.

                            – jennymo
                            Mar 27 '18 at 7:18

















                          • Unfortunately no change. Still the same error with this code.

                            – jennymo
                            Mar 27 '18 at 7:18
















                          Unfortunately no change. Still the same error with this code.

                          – jennymo
                          Mar 27 '18 at 7:18





                          Unfortunately no change. Still the same error with this code.

                          – jennymo
                          Mar 27 '18 at 7:18











                          0














                          You could use my code from here https://github.com/konarshankar07/magento2-cms-hero-image.
                          It will help you to fix your issue. Can you please add more code like di.xml code and upload.php code? It might be easy for me to fix this issue



                          Thanks






                          share|improve this answer



























                            0














                            You could use my code from here https://github.com/konarshankar07/magento2-cms-hero-image.
                            It will help you to fix your issue. Can you please add more code like di.xml code and upload.php code? It might be easy for me to fix this issue



                            Thanks






                            share|improve this answer

























                              0












                              0








                              0







                              You could use my code from here https://github.com/konarshankar07/magento2-cms-hero-image.
                              It will help you to fix your issue. Can you please add more code like di.xml code and upload.php code? It might be easy for me to fix this issue



                              Thanks






                              share|improve this answer













                              You could use my code from here https://github.com/konarshankar07/magento2-cms-hero-image.
                              It will help you to fix your issue. Can you please add more code like di.xml code and upload.php code? It might be easy for me to fix this issue



                              Thanks







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Jan 14 at 16:17









                              ShankarShankar

                              13227




                              13227





















                                  0














                                  You could try my personal code for the image uploader on Ui component



                                   <field name="banner_image">
                                  <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">template</item>
                                  <item name="label" xsi:type="string" translate="true">Banner 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">Vendor_Module/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="vendor_module/template_banner/upload"/>
                                  </item>
                                  </item>
                                  </argument>
                                  </field>


                                  app/code/Vendor/Module/view/adminhtml/web/template/image-preview.html



                                  <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>


                                  From Save controller



                                  $data = $this->getRequest()->getPostValue();
                                  $data = $this->_filterPostData($data);
                                  $model->setData($data)->save();


                                  Add another filter for image uploader to avoid error before save



                                  /**
                                  * Filter template data.
                                  *
                                  * @param array $rawData
                                  * @return array
                                  */
                                  protected function _filterPostData(array $rawData)

                                  $data = $rawData;
                                  // @todo It is a workaround to prevent saving this data in category model and it has to be refactored in future
                                  if (isset($data['banner_image']) && is_array($data['banner_image']))
                                  if (!empty($data['banner_image']['delete']))
                                  $data['banner_image'] = null;
                                  else
                                  if (isset($data['banner_image'][0]['name']) && isset($data['banner_image'][0]['tmp_name']))
                                  $data['banner_image'] = $data['banner_image'][0]['name'];
                                  else
                                  unset($data['banner_image']);



                                  return $data;






                                  share|improve this answer



























                                    0














                                    You could try my personal code for the image uploader on Ui component



                                     <field name="banner_image">
                                    <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">template</item>
                                    <item name="label" xsi:type="string" translate="true">Banner 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">Vendor_Module/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="vendor_module/template_banner/upload"/>
                                    </item>
                                    </item>
                                    </argument>
                                    </field>


                                    app/code/Vendor/Module/view/adminhtml/web/template/image-preview.html



                                    <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>


                                    From Save controller



                                    $data = $this->getRequest()->getPostValue();
                                    $data = $this->_filterPostData($data);
                                    $model->setData($data)->save();


                                    Add another filter for image uploader to avoid error before save



                                    /**
                                    * Filter template data.
                                    *
                                    * @param array $rawData
                                    * @return array
                                    */
                                    protected function _filterPostData(array $rawData)

                                    $data = $rawData;
                                    // @todo It is a workaround to prevent saving this data in category model and it has to be refactored in future
                                    if (isset($data['banner_image']) && is_array($data['banner_image']))
                                    if (!empty($data['banner_image']['delete']))
                                    $data['banner_image'] = null;
                                    else
                                    if (isset($data['banner_image'][0]['name']) && isset($data['banner_image'][0]['tmp_name']))
                                    $data['banner_image'] = $data['banner_image'][0]['name'];
                                    else
                                    unset($data['banner_image']);



                                    return $data;






                                    share|improve this answer

























                                      0












                                      0








                                      0







                                      You could try my personal code for the image uploader on Ui component



                                       <field name="banner_image">
                                      <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">template</item>
                                      <item name="label" xsi:type="string" translate="true">Banner 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">Vendor_Module/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="vendor_module/template_banner/upload"/>
                                      </item>
                                      </item>
                                      </argument>
                                      </field>


                                      app/code/Vendor/Module/view/adminhtml/web/template/image-preview.html



                                      <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>


                                      From Save controller



                                      $data = $this->getRequest()->getPostValue();
                                      $data = $this->_filterPostData($data);
                                      $model->setData($data)->save();


                                      Add another filter for image uploader to avoid error before save



                                      /**
                                      * Filter template data.
                                      *
                                      * @param array $rawData
                                      * @return array
                                      */
                                      protected function _filterPostData(array $rawData)

                                      $data = $rawData;
                                      // @todo It is a workaround to prevent saving this data in category model and it has to be refactored in future
                                      if (isset($data['banner_image']) && is_array($data['banner_image']))
                                      if (!empty($data['banner_image']['delete']))
                                      $data['banner_image'] = null;
                                      else
                                      if (isset($data['banner_image'][0]['name']) && isset($data['banner_image'][0]['tmp_name']))
                                      $data['banner_image'] = $data['banner_image'][0]['name'];
                                      else
                                      unset($data['banner_image']);



                                      return $data;






                                      share|improve this answer













                                      You could try my personal code for the image uploader on Ui component



                                       <field name="banner_image">
                                      <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">template</item>
                                      <item name="label" xsi:type="string" translate="true">Banner 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">Vendor_Module/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="vendor_module/template_banner/upload"/>
                                      </item>
                                      </item>
                                      </argument>
                                      </field>


                                      app/code/Vendor/Module/view/adminhtml/web/template/image-preview.html



                                      <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>


                                      From Save controller



                                      $data = $this->getRequest()->getPostValue();
                                      $data = $this->_filterPostData($data);
                                      $model->setData($data)->save();


                                      Add another filter for image uploader to avoid error before save



                                      /**
                                      * Filter template data.
                                      *
                                      * @param array $rawData
                                      * @return array
                                      */
                                      protected function _filterPostData(array $rawData)

                                      $data = $rawData;
                                      // @todo It is a workaround to prevent saving this data in category model and it has to be refactored in future
                                      if (isset($data['banner_image']) && is_array($data['banner_image']))
                                      if (!empty($data['banner_image']['delete']))
                                      $data['banner_image'] = null;
                                      else
                                      if (isset($data['banner_image'][0]['name']) && isset($data['banner_image'][0]['tmp_name']))
                                      $data['banner_image'] = $data['banner_image'][0]['name'];
                                      else
                                      unset($data['banner_image']);



                                      return $data;







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jan 15 at 6:24









                                      Tuyen NguyenTuyen Nguyen

                                      403212




                                      403212





















                                          0














                                          I add the same issue.



                                          Your upload action should be like this :



                                          $result = $this->imageUploader->upload('slide[image]');






                                          share|improve this answer



























                                            0














                                            I add the same issue.



                                            Your upload action should be like this :



                                            $result = $this->imageUploader->upload('slide[image]');






                                            share|improve this answer

























                                              0












                                              0








                                              0







                                              I add the same issue.



                                              Your upload action should be like this :



                                              $result = $this->imageUploader->upload('slide[image]');






                                              share|improve this answer













                                              I add the same issue.



                                              Your upload action should be like this :



                                              $result = $this->imageUploader->upload('slide[image]');







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered May 13 at 15:54









                                              VinzVinz

                                              495313




                                              495313



























                                                  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%2f219907%2fmagento-2-2-weird-files-array-after-image-upload%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

                                                  Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

                                                  Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form