How to edit image URL in node field?
To rename the file, you'll need to use PHP's rename() function. To do so, you'll want to get the file's full local path using drupal_realpath() like so:

// Fetch the local absolute path of our image
$local_path = drupal_realpath($file-&gt;uri);


Once you've renamed the file, you'll need to modify the file URI (and potentially other attributes-- use print_r($file) to check).

The wording in the docs is a little weird to me, it says "when a file has been added to the database" which means to me the file metadata has already been saved to the database. However, the example shown in the docs seems to edit this info (but without using &amp;$file ...?) without having to return the file object. Strange.

Anyway, your code might look something like this:

function mymodule_file_presave($file) {
  if ($file-&gt;type != 'image') {
    return;
  }
  if (!empty($file-&gt;filename)) {

    // Will likely be 'public://'
    $scheme = file_uri_scheme($file-&gt;uri);

    // Get full path of image location
    $local_path = drupal_realpath($file-&gt;uri);

    // Create new name using drupal scheme format
    $new_uri = $scheme.'new_name_here.jpg';

    // Actual OS rename of file
    rename($local_path, drupal_realpath($new_uri);

    // Update $file object with new uri
    $file-&gt;uri = $new_uri;

    // Not sure if this is still needed...
    $file-&gt;destination = $file-&gt;uri;
  }
}