how to rename file before/after upload
Renaming file entity in Drupal 8 can be achieved like this: 

    $file = File::load($file_target_id);
    $new_filename = "filename.png";
    $stream_wrapper = \Drupal::service('file_system')-&gt;uriScheme($file-&gt;getFileUri());
    $new_filename_uri = "{$stream_wrapper}://{$new_filename}";
    file_move($file, $new_filename_uri);


As you can see in this example Drupal file_move function is used here which takes care of everything. You only need to know file target_id which is the file fid.