Wer mit Extbase zB. einen Datei-Upload im Frontend umsetzen will, merkt schnell wie tricky das sein kann. Meist landet man früher oder später bei Helmut Hummel’s Upload Example (https://github.com/helhum/upload_example). Ich habe aber trotzdem einige Zeit benötigt um es zum Laufen zu bringen.
Dmitry Dulepov hat mir vor 2 Tagen gezeigt, wie man das sehr viel einfacher umsetzen kann:
https://stackoverflow.com/questions/54695460/problems-with-…
protected function createFileReference($contentUid, $pid, $fieldName, File $file)
{
$data = [
'sys_file_reference' => [
StringUtility::getUniqueId('NEW') => [
'table_local' => 'sys_file',
'uid_local' => $file->getProperty('uid'),
'tablenames' => 'tt_content',
'uid_foreign' => $contentUid,
'fieldname' => $fieldName,
'pid' => $pid,
]
]
];
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->start($data, []);
$dataHandler->admin = true;
$dataHandler->process_datamap();
}