How to set value of file field with entity_metadata_wrapper How do you set the value of a file field when using the entity_metadata_wrapper?

I've tried doing this in code:

$file = new stdClass();
$file-&gt;uid = 1;
$file-&gt;uri = $file_path;
$file-&gt;filename = basename($file_path);
$file-&gt;filemime = file_get_mimetype($file_path);
$file-&gt;filesize = filesize($file_path);
$file-&gt;status = FILE_STATUS_PERMANENT;
$file-&gt;display = '1';
file_save($file); // I also tried: $file = file_save($file);

$node = array(
  'type' =&gt; 'news_item',
  'uid' =&gt; 1,
  'status' =&gt; 1,
  'comment' =&gt; 0,
  'promote' =&gt; 0,
  'language' =&gt; 'en',
);

$entity = entity_create('node', $node);

$ewrapper = entity_metadata_wrapper('node', $entity);

$ewrapper-&gt;field_document-&gt;set((array) $file); // I also tried: $ewrapper-&gt;field_document-&gt;set($file);

$ewrapper-&gt;save(true);
entity_save('node', $entity);


But I get this exception:

EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityMetadataWrapper-&gt;set() (line 122 of C:\wamp\www\drupal\sites\all\modules\entity\includes\entity.wrapper.inc).


Any help is very mych appreciated.
Well I just found out a simpler and less ugly looking way to set image.

$image_file = A FILE OBJECT; //Lot of choices here : new stdClass(), file_load, etc
$wrapper-&gt;FIELD_NAME-&gt;file-&gt;set($image_file);


Just as taxonomy or node/entity reference, the file field name point on a loaded object, thats how I find out.



:: EDIT a posteriori ::

Here how I would have do it with OP question.

// Get the file
$file = file_save_data(file_get_contents('/my_local_path/img1.jpg'), 'public://remote_name.jpg');

// Wrap' it like one of your French girls
$wrapper = entity_metadata_wrapper('node', $node);

// And set the photo
$wrapper-&gt;field_photo-&gt;file-&gt;set($file);

// And save the node
$wrapper-&gt;save();