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;
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:
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
add a comment |
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:
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
add a comment |
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:
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
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:
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
magento2 php image-upload file-upload array
asked Mar 26 '18 at 14:54
jennymojennymo
1064
1064
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
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>
add a comment |
Change the uploaderConfig to:
<item name="uploaderConfig" xsi:type="array">
<item name="url" xsi:type="string">cssslider/configuration/upload</item>
</item>
Unfortunately no change. Still the same error with this code.
– jennymo
Mar 27 '18 at 7:18
add a comment |
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
add a comment |
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;
add a comment |
I add the same issue.
Your upload action should be like this :
$result = $this->imageUploader->upload('slide[image]');
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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>
add a comment |
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>
add a comment |
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>
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>
answered Jan 14 at 13:53
Marius♦Marius
169k28326696
169k28326696
add a comment |
add a comment |
Change the uploaderConfig to:
<item name="uploaderConfig" xsi:type="array">
<item name="url" xsi:type="string">cssslider/configuration/upload</item>
</item>
Unfortunately no change. Still the same error with this code.
– jennymo
Mar 27 '18 at 7:18
add a comment |
Change the uploaderConfig to:
<item name="uploaderConfig" xsi:type="array">
<item name="url" xsi:type="string">cssslider/configuration/upload</item>
</item>
Unfortunately no change. Still the same error with this code.
– jennymo
Mar 27 '18 at 7:18
add a comment |
Change the uploaderConfig to:
<item name="uploaderConfig" xsi:type="array">
<item name="url" xsi:type="string">cssslider/configuration/upload</item>
</item>
Change the uploaderConfig to:
<item name="uploaderConfig" xsi:type="array">
<item name="url" xsi:type="string">cssslider/configuration/upload</item>
</item>
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Jan 14 at 16:17
ShankarShankar
13227
13227
add a comment |
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
answered Jan 15 at 6:24
Tuyen NguyenTuyen Nguyen
403212
403212
add a comment |
add a comment |
I add the same issue.
Your upload action should be like this :
$result = $this->imageUploader->upload('slide[image]');
add a comment |
I add the same issue.
Your upload action should be like this :
$result = $this->imageUploader->upload('slide[image]');
add a comment |
I add the same issue.
Your upload action should be like this :
$result = $this->imageUploader->upload('slide[image]');
I add the same issue.
Your upload action should be like this :
$result = $this->imageUploader->upload('slide[image]');
answered May 13 at 15:54
VinzVinz
495313
495313
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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