Programmatically upload a file to a custom file field I am trying to update a node and programmatically upload a file.

$nid = 45343;
$node = node_load($nid);

$image_url = 'http://test.com/misc/druplicon.png';
$file = system_retrieve_file($image_url, file_default_scheme().'://products_images/'.basename($image_url), TRUE);

// We save the file to the root of the files directory.
// $file = file_copy($file, 'public://');

$node-&gt;field_custom_file[LANGUAGE_NONE][0] = (array)$file;
node_save($node);


Somehow, it's not working at all. Do I need to add more functions to it?
The following code works for me.

$image_url = 'http://test.com/misc/druplicon.png';    
$file_info = system_retrieve_file($image_url, 'public://documents/', TRUE);

if ($file_info-&gt;fid) {
  $node-&gt;field_custom_file['und'][0]['fid'] = $file_info-&gt;fid;
}

$node_ready = node_submit($node);
node_save($node_ready);