How can I set sys_file_metadata when creating a FAL Object in TYPO3 Extbase

Viewed 226

I'am searching for solution for adding metadata to a sys_file fileObject in TYPO3 Extbase.

I'am adding a file to the storage in this way:

    $resourceFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ResourceFactory::class);
    $storage = $resourceFactory->getDefaultStorage();

    $fileObject = $storage->addFile(
        $temporaryFile,
        $storage->getFolder('some-folder/'),
        $newfilename
    );

And can manipulate a bunch of properties with updateProperties() like so:

    $fileObject->updateProperties(array(
        'name' => 'foo',
    ));

But how can I set further metadata properties in sys_file_metadata like title or alternative texts when I create the file? Is there a documentation out there, how to do this. I have only found this:

https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/Fal/UsingFal/ExamplesFileFolder.html#

But this documentation contains no hints about metadata handling.

1 Answers

I solved it using the MetaDataAspect which is available on a File object.

$metaData = $fileObject->getMetaData();
$metaData->offsetSet('title', 'Image title');
$metaData->save();

Use with care, as the save method is marked as @internal. Also checkout this changelog document, which is the only document I could found.

Related