Search code examples
drupaldrupal-feeds

Drupal Feeds Import Image from image service


I am using Drupal 7 and Feeds to import an image field into a content type article, it does work when the image url is a direct link to the image.

but images that are linking to image handlers:http://business.iafrica.com/apps/imageUtil/view/article/1008937/1/630x385/are not importing.

I have tried:

  • to use the Feeds Tamper Module and Feeds Tamper PHP to try and alter the image name, this results in an invalid URL loading.
  • To use Field Image Grabber, but I have an XML source, not HTML.

here is my source feed url http://resource.thumbtribe.mobi/ds1.portal/portal/1/4/resource/view/maximized/9500187?format=atom_extern

and my Image: URI xpath mapping is: string(link[@rel="enclosure"]/@href)


Solution

  • I managed to solve this by using the feeds tamper module with the following php snippet to save the image and then reference the path on my server.

    $checkext = substr($field, -5);
    
    if (strpos($checkext,'.') == false)
    {
      $filename = str_replace(".","_",microtime(true)).".jpg";
      $output = "public://field/image/".$filename;
      file_put_contents($output, file_get_contents($field));
      return  $output;
    }
    else
    {
      return $field;
    }