On further debugging it looks node_save is not working as expected.
 
node-save() basicall looks as below
 
transaction();
 
try
{
//do node save related steps
rollback();
}catch(Exception)
 
 
Looks during node_save execution, finaly it comes to exception block.

Is it a bug or I am doing some mistake before calling node_save().
 
Regards
kamal

 
On Wed, Oct 10, 2012 at 7:38 AM, Kamal Palei <palei.kamal@gmail.com> wrote:
Dear All
I have spent quite a lot of time to attach an existing file at server side to a newly created node.
I googled quite a bit, almost everywhere the examples are there for file uplaod / save and then attach to a node.
Did not get any documentation thats says how to attach an existing file to a newly created node .
 
At a high level, my code is as below.
 
$node = new stdClass();
$node->type = resume' ;  // a new content type created
node_object_prepare($node);
$node->title = My title';
$node->language = 'en';
$node->uid = 1;
$file_obj = file_load($fid);
$node->field_resume[$node->language][0] = (array)$file_obj; //field_resume is the machine name for file field
node_save($node);

 
Can somebody please let me know what I am missing here?
The new node is created, with no attachment.
How can I get the file to attached to node.
 
Regards
kamal