How do I migrate an image field with migrate 2 module on drupal 6 I have created my .module and .info and (one) .inc file.

I also have successfully used drush mi to import the data minus the images.

The images are in a related table in the database and are not being copied over when I run the migrate class. Here is my code:

    abstract class RoRMigration extends Migration {
     public function __construct() {
     parent::__construct();


     }
   }


    class RoRPagesMigration extends RoRMigration {
      public function __construct() {
      parent::__construct(MigrateGroup::getInstance('pages'));
      $this-&gt;description = t('Ruby on Rails Pages');


$this-&gt;map = new MigrateSQLMap($this-&gt;machineName,
  array(
    'page_id' =&gt; array(
      'type' =&gt; 'int',
      'unsigned' =&gt; TRUE,
      'not null' =&gt; TRUE,
      'description' =&gt; 'Page ID',
      'alias' =&gt; 'pid',
    )
  ),
  MigrateDestinationNode::getKeySchema()
);

$query = db_select('migrate_ror_pages', 'pid')
         -&gt;fields('pid', array('page_id', 'title', 'content_subtitle', 'body_html', 'page_type',
          'redirect_url', 'published', 'meta_data', 'pretty_url'));



$source_fields = array(
 // TODO: Will add these other files later 
 // 'banners' =&gt; t('Banners attached to this page; populated in prepareRow()'),
 // 'files' =&gt; t('Files attached to this page; populated in prepareRow()'),
  'images' =&gt; t('Images attached to this page; populated in prepareRow()'),
);


$this-&gt;source = new MigrateSourceSQL($query, $source_fields);
$this-&gt;destination = new MigrateDestinationNode('page_data');

// Mapped fields
$this-&gt;addFieldMapping('title', 'title');
$this-&gt;addFieldMapping('field_legacy_guid', 'page_id');
$this-&gt;addFieldMapping('field_legacy_content_subtitle', 'content_subtitle');
$this-&gt;addFieldMapping('field_legacy_html_body', 'body_html');
$this-&gt;addFieldMapping('field_legacy_page_type', 'page_type');
$this-&gt;addFieldMapping('field_legacy_redirect_url', 'redirect_url');
$this-&gt;addFieldMapping('field_legacy_published', 'published');
$this-&gt;addFieldMapping('body', 'meta_data');
$this-&gt;addFieldMapping('field_pathauto', 'pretty_url');


// We will get the image data from a related table in prepareRow()
$arguments = MigrateFileFieldHandler::arguments('file_copy', FILE_EXISTS_REPLACE);
$this-&gt;addFieldMapping('field_gallery_images', 'images')
     -&gt;arguments($arguments);


// No unmapped source fields

// Unmapped destination fields
$this-&gt;addUnmigratedDestinations(array('status', 'promote',
  'revision', 'language', 'uid', 'revision_uid', 'created', 'changed', 'teaser', 'sticky', 'field_file_attached_file', 'field_legacy_link', 'field_legacy_byline', 'field_banner_image', 'path', 'pathauto_perform_alias'));
      }

      public function prepareRow($current_row) {

        $source_id = $current_row-&gt;page_id;


// This adds the images to the image_gallery field
$result = db_select('migrate_ror_pages_images', 'pic')
          -&gt;fields('pic', array('filename_path', 'title'))
          -&gt;condition('page_id', $source_id)
          -&gt;execute();
$current_row-&gt;images = array();
foreach ($result as $row) {
  $image_data = array(
    'path' =&gt; $row-&gt;filename_path,
    'alt' =&gt; $row-&gt;title,
    'title' =&gt; $row-&gt;title,
    'description' =&gt; $row-&gt;title,
  );
  $current_row-&gt;images[] = drupal_to_js($image_data);
}

return TRUE;
    }
   }


So to be clear. There are two data tables migrate_ror_pages and migrate_ror_pages_images. The first table imports fine but the images do not import. The image table has a url to the image like this /sites/all/default/files/uploads/page_assets/images/filename.jpg and it has a title column, page_id, and image_id. There are more than one images per page.
Okay so I figured out what was wrong. I needed to put the site url in front of the path in my db.

  public function prepareRow($current_row) {

    $source_id = $current_row-&gt;page_id;


    // This adds the images to the image_gallery field
    $result = db_select('migrate_ror_pages_images', 'pic')
      -&gt;fields('pic', array('filename_path', 'title'))
      -&gt;condition('page_id', $source_id)
      -&gt;execute();
    $current_row-&gt;images = array();
    foreach ($result as $row) {
      $image_data = array(
       'path' =&gt; $row-&gt;$GLOBALS['base_url'] . filename_path,
       'alt' =&gt; $row-&gt;title,
       'title' =&gt; $row-&gt;title,
       'description' =&gt; $row-&gt;title,
      );
      $current_row-&gt;images[] = drupal_to_js($image_data);
     }


The line that needed to be changed was the one regarding the path to the image. I was using a relative path /sites/default/.../filname.jpg and I needed to use a full path:

           'path' =&gt; $row-&gt;$GLOBALS['base_url'] . filename_path,


So if you are trying to import images/files you will need a full path to the image not a relitave one!

Hopes this helps someone.

//Craig