<p>I don't know if you're still facing this issue but it's something I'm working on right now! Basically my solution was to create a short program to parse through the Element Exporter json and to change anything that was an Asset ID to that asset's url (which Feed Me accepts).</p>
<pre class="lang-php prettyprint-override"><code>    public function modifyExport(array $element): array {
        $result = [];
        //Parse through JSON export
        foreach ($element as $key =&gt; $value) {
            //Recursive function to keep traversing down levels
            if (is_array($value)) {
                $result[$key] = $this-&gt;modifyExport($value); 
            //You've reached a root level, check the content
            } else {
                //If the value is a number, it is representing an ID
                if (is_numeric($value)) {
                    //Find the Element corresponding to this id
                    $assetCheck = Craft::$app-&gt;getElements()-&gt;getElementTypeById(intval($value));
                    //Check if the element is an asset
                    if ($assetCheck == 'craft\\elements\\Asset') {
                        //Get the actual asset data
                        $asset = Craft::$app-&gt;getElements()-&gt;getElementById(intval($value));
                        //Create the asset path *this may differ based on where your assets are*
                        $path = getEnv('DEFAULT_SITE_URL') . '/assets/images/' . $asset-&gt;folderPath . $asset-&gt;filename;
                        //Rewrite the content with the path, instead of the id
                        $result[$key] = $path;
                    //If the element is not an asset, keep it the same
                    } else {
                        $result[$key] = $value;
                    }
                     
                }
            }
        }
        return $result;
    }
</code></pre>
<p>Once I got the result, I used <code>file_put_contents('end/path/goes/here.json', json_encode('result here'));</code> to place it in a different file OR you can simply overwrite the same export file. Hope this helps!</p>

CC BY-SA 4.0
2021-02-10T16:15:37.427Z
2021-02-12T15:39:33.997Z
2021-02-12T15:39:33.997Z
Jessica Zalzman
<p>When I export data using Craft's built-in <a href="https://docs.craftcms.com/v3/extend/element-exporter-types.html" rel="nofollow noreferrer">Element Exporter</a>, asset fields are exported with an element ID. This is the same as Category and Entry fields, for example.</p>

<p>However, when mapping fields in Feed Me, asset fields do not allow you to select ID as the provided data, like a Category or Entry field would. When you run import, these fields seem to be skipped as the provided data is not what Feed Me is looking for.</p>

<p>Perhaps I'm missing something here, but Element Exporter and Feed Me don't seem compatible when it comes to asset fields at the moment. Has anyone else had any luck using these two programs together with regards to assets?</p>

<plugin-feedme><assets-field><export>
Importing assets with Feed Me using Element Exporter data
# Importing assets with Feed Me using Element Exporter data

(Asked by: username_0 on 2020-04-28)

When I export data using Craft's built-in [Element Exporter](https://docs.craftcms.com/v3/extend/element-exporter-types.html), asset fields are exported with an element ID. This is the same as Category and Entry fields, for example.

However, when mapping fields in Feed Me, asset fields do not allow you to select ID as the provided data, like a Category or Entry field would. When you run import, these fields seem to be skipped as the provided data is not what Feed Me is looking for.

Perhaps I'm missing something here, but Element Exporter and Feed Me don't seem compatible when it comes to asset fields at the moment. Has anyone else had any luck using these two programs together with regards to assets?

**Tags:** plugin-feedme, assets-field, export

---

## 1 answers

### Answer by username_1 on 2021-02-10. Score: 1

I don't know if you're still facing this issue but it's something I'm working on right now! Basically my solution was to create a short program to parse through the Element Exporter json and to change anything that was an Asset ID to that asset's url (which Feed Me accepts).
    public function modifyExport(array $element): array {
        $result = [];
        //Parse through JSON export
        foreach ($element as $key => $value) {
            //Recursive function to keep traversing down levels
            if (is_array($value)) {
                $result[$key] = $this->modifyExport($value); 
            //You've reached a root level, check the content
            } else {
                //If the value is a number, it is representing an ID
                if (is_numeric($value)) {
                    //Find the Element corresponding to this id
                    $assetCheck = Craft::$app->getElements()->getElementTypeById(intval($value));
                    //Check if the element is an asset
                    if ($assetCheck == 'craft\\elements\\Asset') {
                        //Get the actual asset data
                        $asset = Craft::$app->getElements()->getElementById(intval($value));
                        //Create the asset path *this may differ based on where your assets are*
                        $path = getEnv('DEFAULT_SITE_URL') . '/assets/images/' . $asset->folderPath . $asset->filename;
                        //Rewrite the content with the path, instead of the id
                        $result[$key] = $path;
                    //If the element is not an asset, keep it the same
                    } else {
                        $result[$key] = $value;
                    }
                     
                }
            }
        }
        return $result;
    }

Once I got the result, I used file_put_contents('end/path/goes/here.json', json_encode('result here')); to place it in a different file OR you can simply overwrite the same export file. Hope this helps!


---

