'TYPO3 11: convert t3 file uri into file identifier

How can I convert the TYPO3 file uri t3://file?uid=54 to be usable for other TYPO3 methods which need a file identifier? The file uri is returned by a flexform which selects a XML file. This XML file should be read. However I cannot find a useful API function in the TYPO3 Core.

$paramTestFile = 't3://file?uid=54';
$xmlString = GeneralUtility::getURL($paramTestFile);

The above code fails for TYPO3 URIs.

The file reference with uid=54 is at "fileadmin/example.xml". The Filelist backend module shows the details of this file. However I need this file path also in the PHP code in order to read in the file.

use TYPO3\CMS\Core\LinkHandling\FileLinkHandler;

$fileHandler = GeneralUtility::makeInstance(FileLinkHandler::class);
$fileInfo = $fileHandler->asString($paramTestFile);

It is not possible to use $paramTestFile in the above example. The class FileLinkHandler and its method asString does exactly the opposite of what I need.

$content = @file_get_contents($url);

However the absolute file path is needed for the read method . How can I convert the FAL file URI into the file identifier?

use TYPO3\CMS\Core\Resource\StorageRepository;

$storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
$defaultStorage = $storageRepository->getDefaultStorage();
$fileInfo = $defaultStorage->getFileByIdentifier($paramTestFileIdentifier);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source