How do I check the content type of a file using hook_file_presave I wrote a module to strip Exif data from uploaded file.

function modulename_file_presave(Drupal\file\FileInterface $file) {
if ($file-&gt;getMimeType() == 'image/jpeg') {
  $filepath = \Drupal::service('file_system')-&gt;realpath($file-&gt;getFileUri());
  $path = $file-&gt;getFileUri();
  $img = new Imagick($path);
  $img-&gt;stripImage();
  $img-&gt;writeImage($filepath);
  $img-&gt;clear;
}


it works to all files, but I want to restrict this module to work in only specific content type.
How can I get the content type in my module? 
Thank you.
The file itself has no reference to the parent node (it can be referenced by multiple entities). But you can get the node type you are adding or the node you are editing when you upload the file from the route:

function modulename_file_presave(\Drupal\file\FileInterface $file) {
  if ($file-&gt;getMimeType() == 'image/jpeg') {
    switch (\Drupal::routeMatch()-&gt;getRouteName()) {
      case 'node.add':
        $content_type = \Drupal::routeMatch()-&gt;getRawParameter('node_type');
        break;

      case 'entity.node.edit_form':
        $node = \Drupal::routeMatch()-&gt;getParameter('node');
        $content_type = $node-&gt;getType();
        break;

      default:
        $content_type = NULL;
    }
  }
}