2

In past i have implement a FAL frontend upload in different ways, for example with own file reference models and so on. I've also tried the upload example extension of helhum https://github.com/helhum/upload_example. But the files would be saved also if validation failed. So I have many trash files at the webserver. Now i look for a posibility to implement an FAL upload with TYPO3 core functions. Or is there a best practice to handle an FAL upload without data trash?

freshp
  • 525
  • 5
  • 20
  • I have post this question in slack. Possibly Answers I enter here. – Jan Männig Sep 14 '16 at 21:01
  • 1
    I would just add a cleanup command which cleans up the unneeded files. All other is fine – Georg Ringer Sep 15 '16 at 03:13
  • In this case it´s possible to flood the server with files. isn´t it? – freshp Sep 15 '16 at 14:39
  • What validation fails? The validation of the file itself or another form a field? The idea of Helmut's approach is that you can re-send the form if validation of one of the form fields failed without uploading the file again. But maybe you can describe your use case for the form? – minifranske Sep 15 '16 at 20:36
  • The use case is, i have a form with different validations, mandatory fields for example. If a user select an file to upload and let mandatory fields empty the validation of the hole form failed. But the file is uploaded. If the user now gone away without to send als valid form input then i have unnecessary files on my server. – Jan Männig Sep 16 '16 at 07:37

1 Answers1

0

Concerning the outlined use-case (file upload succeeded, rest of the form had validation errors, user quit session) I'd suggest to store uploaded files to some temporary folder and move them to another location once the whole model is valid and can be persisted using the repository.

Following Helmut's example it's possible to define the temporary upload folder in the controller logic

$uploadConfiguration = [
    UploadedFileReferenceConverter::CONFIGURATION_UPLOAD_FOLDER
        => '1:/temporary-uploads/',
];
$this->arguments[$argumentName]
    ->getPropertyMappingConfiguration();
    ->forProperty('image')
    ->setTypeConverterOptions(
        UploadedFileReferenceConverter::class,
        $uploadConfiguration
    );

Then in the specific controller action move the file to the real folder

$model->getImage()->getOriginalResource()->moveTo(
    ResourceFactory::getInstance()->retrieveFileOrFolderObject(
        '1:/valid-uploads/'
    )
);

All unfinished attempts are stored in a dedicated folder and can then be purged by some scheduled task.

Oliver Hader
  • 4,093
  • 1
  • 25
  • 47