Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete uploaded resource after failed validation #174

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

fdchriswaechter
Copy link

Problem: When a file is uploaded using the FormUpload element, it is immediately saved to the resource collection upon form submission. However, if the file is later deemed invalid, it still occupies server storage, leading to unnecessary and potentially significant consumption of storage space.

Implementation: The \Neos\Form\Validation\FileTypeValidator now utilizes an injected resource manager. If a file fails validation, the resource manager deletes the corresponding file and entry in the DB, preventing invalid files from being permanently stored and conserving server storage space.

@kitsunet
Copy link
Member

Thank you for this fix! I understand the problem and there might not be a good place to fix this, my only worry would be that this deletes the file in some cases but not in others (for example if the validation fails on something else and no resubmit happens).

I'll have a closer look.

Copy link
Member

@bwaidelich bwaidelich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution and sorry for the -1 but I don't think that a validator should have side effects – especially not such dramatic ones.
We could make it configurable I suppose, but I would suggest to go a different route.
For example we could hook into the form submission to remove invalid files. But we would always have the hen-egg situation that @kitsunet described.
So instead we should promote (and document) how to use protected (and temporary?) resourceCollections and a finisher that publishes the file to some public collection (if that's needed at all, for storing/sending the file it is not) like suggested with neos/form-builder#137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants