Typo3v11 Upload files from frontend with custom Extension (extension builder)

67 Views Asked by At

i created a custom extension with extensionBuilder and have a modal with a file attribute, I can create a new record with any file from backend, but i need to add the same functionality in frontend as well and couldn't find a solution

I tried simply putting a file tag in the form

<f:form.upload name="file" property="file" />

but got this error

Exception while property mapping at property path "file": The identity property "Screenshot from 2024-01-05 14-44-55.png" is no UID.

this is my createAction in my controller

public function createAction(\..\..\Domain\Model\Announcements $newAnnouncements) {
    $this->announcementsRepository->add($newAnnouncements);
    $this->redirect('list');
}

this is my tca if needed

'file' => [
        'exclude' => true,
        'label' => 'LLL:EXT:../Resources/Private/Language/locallang_db.xlf:tx_.._domain_model_announcements.file',
        'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
            'file',
            [
                'appearance' => [
                    'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:media.addFileReference'
                ],
                'overrideChildTca' => [
                    'types' => [
                        '0' => [
                            'showitem' => '
                            --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                            --palette--;;filePalette'
                        ],
                        \TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
                            'showitem' => '
                            --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                            --palette--;;filePalette'
                        ],
                        \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
                            'showitem' => '
                            --palette--;;imageoverlayPalette,
                            --palette--;;filePalette',
                        ],
                        \TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [
                            'showitem' => '
                            --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                            --palette--;;filePalette'
                        ],
                        \TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [
                            'showitem' => '
                            --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                            --palette--;;filePalette'
                        ],
                        \TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
                            'showitem' => '
                            --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                            --palette--;;filePalette'
                        ]
                    ],
                ],
                'foreign_match_fields' => [
                    'fieldname' => 'file',
                    'tablenames' => 'tx_**_domain_model_announcements',
                    'table_local' => 'sys_file',
                ],
                'maxitems' => 1
            ]
        ),
        
    ],
1

There are 1 best solutions below

0
On

Maybe this article in the TYPO3 documentation will help you.

Confirm that your controller action includes validation for file uploads. You may need to adjust the createAction method to handle file uploads correctly.