-1

I am using feeds to import a heavily customised wordpress site into drupal using xpath and a custom xml file. All is going well until I try to import multiple images into a node.

The image field is a multi value field (not multiple different image fields)

Only the first image is imported the rest are ignored.

When I have xpath debugging on it correctly shows multiple image URI's and their titles.

Is there a way using feeds and xpath to import multiple images into a node?

This is an example of one item from the feed

<root>
    <item>
        <wordpress_id>85672</wordpress_id>
        <title>.....</title>
        <content>.....</content>
        <created>2017-03-17 10:13:24</created>
        <custom_fields>
            <url type="Website">......</url>
            <url type="Website2">.....</url>
        </custom_fields>
        <attachments>
            <images>
                <item>
                    <ID>85671</ID>
                    <post_author>0</post_author>
                    <post_date>2017-03-08 18:00:00</post_date>
                    <post_title>.....</post_title>
                    <uri>.....</uri>
                </item>
                <item>
                    <ID>85671</ID>
                    <post_author>0</post_author>
                    <post_date>2017-03-08 18:00:00</post_date>
                    <post_title>.....</post_title>
                    <uri>......</uri>
                </item>
            </images>
        </attachments>
    </item>   
</root>

The post title and uri from the attachments are the two fields I am trying to map to the node image type

for my xpath I am referencing them using...

image_title => attachments/images/item/post_title
image_source => attachments/images/item/uri

and in my mapping I am using...

image_title (image_title) => Image: Title (field_image:title)
image_source (image_source) =>  Image: URI (field_image:uri)

in the section I have no trouble mapping website and website2 to to a multi value link field so I am not sure why the image field should be any different.

edit: added xml snippet and mappings and further explanation

  • Try the Feeds Import Preview module. This may reveal where your configured xpaths went wrong. – MegaChriz Sep 20 '17 at 15:00
  • Thanks; Feeds Import Preview showed the import was correctly formatted with no errors. It appears the issue was not with the importer but the original image, see my answer below. – DeveloperChris Sep 21 '17 at 7:12
0

You will need to use the feeds tamper module: https://www.drupal.org/project/feeds_tamper

With this module you can alter (tamper) the content of the (XML-)feed values. One of the tamper-functions allows you to split the value at the comma (or other character you set) so then you can import all the images in this field.

An example XML like this could all be imported into one image field.

<xml>
    <node>
        <images>file_1.jpg, file_2.jpg, file_3.jpg</images>
    </node>
</xml>
  • I have added some more info. isn't the use of feeds tamper to explode the comma delimited list into separate entities? why do I need to do this if the items are already separate. the custom websites works just fine. If I do this how then do I extract the matching titles? see xml snippet above. – DeveloperChris Sep 20 '17 at 11:42
0

The issue was resolved.

Feeds importer was working correctly all along. The problem it seems was with the actual images themselves. I didn't realise, but the in some cases the source images where huge (in excess of 18Mb) It just co-incidentally happened that the large image was the second image for the node. Thus when the feeds importer failed. It actually looked like it worked but only managed to import the first image.

When I resized all the images and then re-imported them, it imported all the images correctly.

There is still an unresolved issue in that the import was failing silently. After a few tweaks import suddenly failed with server 500 errors. That's when the apache logs showed a memory allocation error.

Once I saw that, I was able to determine the issue was related to the source images.

I guess the outcome of this is don't assume the problem is related to something you did.

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.