How to migrate files into a field with unlimited values (D6 -> D7) I am currently migrating a D6 site into D7 and so far everything has gone smoothly. I use migrate and migrate_d2d. 

But now I am stuck :-(. I have an image field with unlimited values (a slideshow) and into that field I need to import images from the corresponding slideshow in the legacy site. My problem is that after import only one image is imported (the last one in the slideshow). How do I make every picture end up in its own subfield?
In my prepareRow() I am trying to use the loop below. I fetch the field ID from $row->fields_productimages[#] (index > 2 are field ID's that belong to the slideshow). I then get the file path from the legacy database and use that path to import the image. But as I said, only the last image is attached to my field.
There are no error messages. Any help is appreciated.

$i = 2;
if($row-&gt;field_productimages[$i] != ''){
    while($row-&gt;field_productimages[$i] != ''){
        $fid = $row-&gt;field_productimages[$i];
        $filepath = Database::getConnection($target='default', $key='legacy')-&gt;query('SELECT f.filepath FROM {files} f WHERE f.fid = :fid',array(':fid' =&gt; $fid))-&gt;fetchAssoc();
        $this-&gt;addFieldMapping('field_bildspel_instrument')-&gt;defaultValue($filepath);   
        $this-&gt;addFieldMapping('source_dir')-&gt;defaultValue('http://www.mysite.se/');
        $this-&gt;addFieldMapping('destination_dir')-&gt;defaultValue('public://instrument/bildspel');    
        $this-&gt;addFieldMapping('field_bildspel_instrument:file_replace')-&gt;defaultValue('FILE_EXISTS_REPLACE');
        $this-&gt;addFieldMapping('field_bildspel_instrument:file_class')-&gt;defaultValue('MigrateFileUri');
        $this-&gt;addFieldMapping('field_bildspel_instrument:title', 'field_sensorimage:title');   
        $this-&gt;addFieldMapping('field_bildspel_instrument:preserve_files')-&gt;defaultValue(1);    
        $this-&gt;addFieldMapping('field_bildspel_instrument:urlencode')-&gt;defaultValue(1); 
        $i++;
    }
}
Finally figured it out. The image field with unlimited values needs a default value with file paths presented as an array. As the array in $filepath was 2 dimensional (an array in an array), I needed two foreach loops to get down to the simple array needed. This is now a working example, I publish it here in case somebody have the same question:

$i = 2;
$filepath = array();
if($row-&gt;field_productimages[$i] != ''){
    while($row-&gt;field_productimages[$i] != ''){
        $fid = $row-&gt;field_productimages[$i];
        $filepath[] = Database::getConnection($target='default', $key='legacy')-&gt;query('SELECT f.filepath FROM {files} f WHERE f.fid = :fid',
        array(':fid' =&gt; $fid))-&gt;fetchAssoc();
        $i++;
    }
    foreach ($filepath as $value1){
        foreach ($value1 as $value){
          $files[] = $value;
        }
    }
    $this-&gt;addFieldMapping('field_bildspel_instrument')-&gt;defaultValue($files);  
    $this-&gt;addFieldMapping('field_bildspel_instrument:source_dir')-&gt;defaultValue('http://www.myoldsite.se/');
    $this-&gt;addFieldMapping('destination_dir')-&gt;defaultValue('public://product/slideshow');  
    $this-&gt;addFieldMapping('field_bildspel_instrument:file_replace')-&gt;defaultValue('FILE_EXISTS_REUSE');
    $this-&gt;addFieldMapping('field_bildspel_instrument:file_class')-&gt;defaultValue('MigrateFileUri');
    $this-&gt;addFieldMapping('field_bildspel_instrument:title', 'field_productimages:title'); 
    $this-&gt;addFieldMapping('field_bildspel_instrument:preserve_files')-&gt;defaultValue(1);    
    $this-&gt;addFieldMapping('field_bildspel_instrument:urlencode')-&gt;defaultValue(1);     
}