You are not on your own

On the one hand:

In a frontend context [...] there is no specific API to create a File Reference. You are on your own.

Working With Files, Folders and File References – Creating a File Reference – In the Frontend Context

On the other hand:

use TYPO3\CMS\Core\Resource\FileReference as FileReferenceCore;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference as FileReferenceExtbase;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;

/** @var ResourceFactory */
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$file = $resourceFactory->getFileObjectFromCombinedIdentifier(
    $myCombinedIdentifier
);

/** @var FileReferenceCore */
$fileReferenceCore = GeneralUtility::makeInstance(
    FileReferenceCore::class,
    ['uid_local' => $file->getUid()]
);
/** @var FileReferenceExtbase */
$fileReferenceExtbase = GeneralUtility::makeInstance(FileReferenceExtbase::class);
$fileReferenceExtbase->setOriginalResource($fileReferenceCore);

/** @var ObjectStorage */
$objectStorage = GeneralUtility::makeInstance(ObjectStorage::class);
$objectStorage->attach($fileReferenceExtbase);

$frontendUser->setImage($objectStorage);

#webdev #TYPO3

Werdings Tiere · Discuss... · write.as