I have drupal 7 installation with file field + video field(and media module). I can change where to upload files in video field setting(default: videos/original). I'm trying to do stuff to videos after file is uploaded and node is saved. Is there a hook I can use to achieve this?

What I want Exactly: Make a copy of the videos to 2 different servers via ftp and some transcode codes. First file needs to be uploaded to drupal folder and after that I need my code to run. sometimes videos need to be converted using ffmpeg(move to videos/converted) and then I run my code.

I've found these hooks but none of theme get called after uploading files or even after saving the node:

hook_file_copy($file, $source)

hook_file_move($file, $source)

how about this one?

hook_field_insert or hook_node_insert

1 Answer 1


hook_node_insert() and/or hook_node_update() would probably be the right place to do this. Your code might look something like this:

function MYMODULE_node_insert($node) {
  // See if a file has been added
  if ($file_items = field_get_items('node', $node, 'field_file')) {
    // Get the first file item
    $file_item = array_shift($file_items);

    // Load the file object from the cache/database
    $file = file_load($file_item['fid']);

    // The path to the file is in $file->uri

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.