How to migrate fields attached to files? I'm writing a file migration using migrate/migrate_d2d to migrate files from one Drupal 7 installation to another.

Images have custom fields attached to them, including a text field "field_boilerplate". This field exists in the destination site's image type. When I run the migration, the image itself migrates and creates an image entity, but field_boilerplate is not populated.

What am I doing wrong, and how can I migrate fields attached to files?

In mymodule.module:

/**
 * Implements hook_flush_caches().
 */
function mymodule_flush_caches() {
  mymodule_migrate_register_classes();
}
/**
 * Register dynamic migration classes
 */
function mymodule_migrate_register_classes() {
  // Arguments common to all migrations
  $common_args = array(
    'source_connection' =&gt; 'mysite_legacy',
    'source_version' =&gt; 7,
    'group_name' =&gt; 'mymodule_migration',
  );
  // Other migration arguments redacted for length
  // Image migration arguments
  $image_args = array(
    'machine_name' =&gt; 'images',
    'class_name' =&gt; 'MyModuleImageMigration',
    'description' =&gt; t('Migrate images'),
    'user_migration' =&gt; 'users',
    'default_uid' =&gt; 1,
    'source_dir' =&gt; 'http://example.com/sites/default/files',
    'destination_dir' =&gt; 'public://',
    'skip_pictures' =&gt; TRUE,
  );
  Migration::registerMigration('MyModuleImageMigration', 'images', $image_args + $common_args);
}
/**
 * Implements hook_migrate_api().
 */
function mymodule_migrate_api() {
  return array('api' =&gt; 2);
}


In an included file:

&lt;?php
class MyModuleImageMigration extends DrupalFile7Migration {
  public function __construct($arguments) {
    parent::__construct($arguments);
    // Mappings
    $this-&gt;addFieldMapping('field_boilerplate', 'field_boilerplate');
  }
}
You need to specify the bundle type when registering the dynamic migration:

  $image_args = array(
    'machine_name' =&gt; 'images',
    'class_name' =&gt; 'MyModuleImageMigration',
    'description' =&gt; t('Migrate images'),
    'user_migration' =&gt; 'users',
    'default_uid' =&gt; 1,
    'source_dir' =&gt; 'http://example.com/sites/default/files',
    'destination_dir' =&gt; 'public://',
    'skip_pictures' =&gt; TRUE,
    'bundle' =&gt; 'image', // Need to add the bundle type
  );
  Migration::registerMigration('MyModuleImageMigration', 'images', $image_args + $common_args);