Add value to field using Entity Metadata Wrapper I'm trying to accomplish the seemingly simple task to add a value to a multi-value file field in Drupal 7. I have been trying for hours, but none of the answers I found would solve my problem.

My field is called field_video_ext. Using the Remote Stream Wrapper module, I would like to add values like this (using some of the module's code):

&lt;?php

// My videos and their respective nodes.
$videos = array(
  array(
    'nid' =&gt; '1903',
    'uri' =&gt; 'http://example.com/movie.flv',
  ),
  array(
    'nid' =&gt; '3172',
    'uri' =&gt; 'http://example.com/movie2.flv',
  ),
);

foreach ($videos as $video) {
  // From the Remote Stream Wrapper module.
  try {
    $file = remote_stream_wrapper_file_load_by_uri($video['uri']);
    if (!$file) {
      $file = remote_stream_wrapper_file_create_by_uri($video['uri']);
      file_save($file);
    }
  }
  catch (Exception $e) {
    drupal_set_message($e-&gt;getMessage());
  }

  if (empty($file-&gt;fid)) {
    drupal_set_message(t('Unable to add file from URL %file.', array('%file' =&gt; $video['uri'])));
    exit;
  }
  // Display needs to be set.
  $file-&gt;display = 1;

  // Get Entity Metadata Wrapper
  $wrapper = entity_metadata_wrapper('node', $video['nid']);

  // Write information into fields.
  $wrapper-&gt;field_video_ext-&gt;set(get_object_vars($file));

  // Save wrapper.
  $wrapper-&gt;save();

}

?&gt;


Now the problem is that this doesn't work if the field accepts multiple values. It throws the error 


  EntityMetadataWrapperException: Invalid data value given for wrapper
  chain


I then tried using $wrapper-&gt;field_video_ext[] = get_object_vars($file);, but that doesn't work either. I think it was this error I got:


  Fatal error: Cannot use object of type Project as array


I also tried the following instead of get_object_vars($file):

$file = (array) $file;
$items = array($file);


And then saving that array using set() or the [] way. But to no avail. Can anybody tell me what I am doing wrong?
One issue may be that get_object_vars() returns an array with keys that the file field does not understand.  The EntityMetadataWrapper documentation provides two options for setting file reference values, though it appears to use single value fields in the examples:

Setting the file directly:

$w_containing_node-&gt;field_attachment_content-&gt;file-&gt;set( $file_obj );


Providing an array with just fid:

$w_containing_node-&gt;field_attachment_content-&gt;set( array('fid' =&gt; $fid) )




One of the comments provides the following examples from the entity tests which apply to a multi-value field, though I'm not sure if setting the full file object will work appending a new item:

$wrapper-&gt;field_file[0] = array('fid' =&gt; $file-&gt;fid, 'display' =&gt; TRUE);
$wrapper-&gt;field_file[1]-&gt;file = $file;