Attach an Existing File to a Node... Programmatically

and the need to consider languages / translations.

Hi!! I'm excited 'cause I just spent another hour figuring out something that wasn't exactly rocket science... but a fairly obscure solution for my "special case".

I followed the advice HERE to complete my node_save based solution and ended up in a tough situation.

The files attached to the nodes just fine. You could view the node and download the file just fine. But you couldn't see the file on the 'Edit' screen. That would make it impossible to do any updates to the node since the file is a required field.

The bottom line is this: You need to add the actual language to the file array to get around this. (Update: this may not be true but it worked this way for me on a multi-language site.)

So instead of (as mentioned in the article above):

  $node->field_image[LANGUAGE_NONE][0] = (array)$file;

Do THIS (choosing the proper language for your case):

  $node->field_image['en'][0] = (array)$file;

See the actual function I used here.. view the function