I have a custom ImageUploader

Issue : When I try to create a new Object, the image field appears and works fine. Image send to my media dir and the name saved in database. But, when I try to edit the previously created object, my objet has all his fields registered; but the image field is missing



Here comes the field in ui component

    <field name="image" sortOrder="40" formElement="imageUploader">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="source" xsi:type="string">miseenavant</item>
            <item name="previewTmpl" xsi:type="string">Cpy_MiseEnAvant/image-preview</item>
            <label translate="true">Mise En Avant Image</label>
                        <param xsi:type="url" name="url" path="mev/image/upload"/>
                    <openDialogTitle>Media Gallery</openDialogTitle>
                    <allowedExtensions>jpg jpeg gif png</allowedExtensions>

It seems to be related to my dataprovider

public function getData()
    $data = [];
    if($id = $this->request->getParam('id')) {
        $mev = $this->mevFactory->create()->load($id);
        $data[$id] = $mev->getData();
    try {
            $currentStore = $this->storeManager->getStore();
            $mediaUrl = $currentStore->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
            $data[$id]['image'] = array($mediaUrl.$this->mevHelper::MEV_MEDIA_DIRECTORY.$data[$id]['image']);
    } catch (NoSuchEntityException $e) {
    return $data;

Looks like i'm sending an array as image when it should be an object probably, cause I see this error in console :

file-uploader.js:171 Uncaught TypeError: Cannot create property 'previewType' on string 'http://mywebsite/media/mev_image/upload/60d2f7eb55bd8.png

Edit : There is is the best I can do digging :/


        'initialMediaGalleryOpenSubpath' => 'mev_image/upload',
        'name' => $data[$id]['image'],
        'file' => $data[$id]['image'],
        'previewType' => 'image',
        'type' => 'image/png',
        'path' => $mediaUrl.$this->mevHelper::MEV_MEDIA_DIRECTORY,
        'url' => $mediaUrl.$this->mevHelper::MEV_MEDIA_DIRECTORY.$data[$id]['image']
$data[$id]['image'] = array($this->image);        

1 Answer 1


You have to pass image array that contains image url,name. For passing it to ui component you can use dataprovider

<argument name=""class"" xsi:type=""string"">Namespace\Modulen\Model\Modelname\DataProvider</argument>

pass array like below.

$categoryData['image'][0]['name'] = $category->getData('image');
$categoryData['image'][0]['url'] = $category->getImageUrl();

for reference you can look


Magento 2 ui component image upload

  • Forgot to update the issue but it's indeed how i manage to did it more or less with may be some different data, but, going with an array is the way.
    – Claims
    Jul 28, 2021 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.