code: protected static function getVirtualFileObject($fileName, array $metadata)
      {
          /** @var \TYPO3\CMS\Core\Resource\ResourceFactory $resourceFactory */
          $resourceFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ResourceFactory::class);
  
          $recordData = [
              'uid' => 0,
              'pid' => 0,
              'name' => 'Temporary Upload Storage',
              'description' => 'Internal storage, mounting the temporary PHP upload directory.',
              'driver' => 'Local',
              'processingfolder' => '',
              // legacy code
              'configuration' => '',
              'is_online' => true,
              'is_browsable' => false,
              'is_public' => false,
              'is_writable' => false,
              'is_default' => false,
          ];
          $storageConfiguration = [
              'basePath' => PathUtility::dirname($fileName),
              'pathType' => 'absolute'
          ];
  
          $virtualStorage = $resourceFactory->createStorageObject($recordData, $storageConfiguration);
          $name = PathUtility::basename($fileName);
          $extension = strtolower(substr($name, strrpos($name, '.') + 1));
  
          /** @var \TYPO3\CMS\Core\Resource\File $virtualFileObject */
          $virtualFileObject = GeneralUtility::makeInstance(
              \TYPO3\CMS\Core\Resource\File::class,
              [
                  'identifier' => '/' . $name,
                  'name' => $name,
                  'extension' => $extension,
              ],
              $virtualStorage,
              $metadata
          );
  
          return $virtualFileObject;
      }
docs: Creates a virtual File object to be used transparently by external
  metadata extraction services as if it would come from standard FAL.
  
  @param string $fileName
  @param array $metadata
  @return \TYPO3\CMS\Core\Resource\File