[MGNLFORM-254] add server side validation for file upload fields Created: 09/Dec/14  Updated: 04/Jun/15  Resolved: 20/May/15

Status: Closed
Project: Magnolia Form Module
Component/s: field, validation
Affects Version/s: 2.2.8
Fix Version/s: 2.2.13

Type: Improvement Priority: Neutral
Reporter: Richard Gange Assignee: Christoph Meier
Resolution: Fixed Votes: 1
Labels: support
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File allowed-mime-types-list.png    
Issue Links:
causality
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Release notes required:
Yes
Date of First Response:

 Description   

We need server side validation for file upload fields on a form.

Please see SUPPORT-3995 for donated code to handle it.



 Comments   
Comment by Ravish Bhagdev [ 20/Dec/14 ]

SUPPORT-3995 doesn't seem accessible from community account at least. Can you please copy the details here?

Comment by Ravish Bhagdev [ 30/Jan/15 ]

Will be good if we can allow the user to specify allowed file types/extensions and also max file size.

Comment by Christoph Meier [ 20/May/15 ]

The form module now configures a new validator in the node /modules/form/config/validators/fileUpload
it has the following defaults (which are not bootstrapped)
— i18nBasename (default: info.magnolia.module.form.messages)
— maxFileSize (default: 10485760 (bytes))
The validator also defines a list of allowed mime-types. If omitted, every mime type is allowed! See screenshot for what is defined per default. (Customers should adapt it according to their wishes.)

In the case of an error, 2 different message keys are returned
— form.user.errorMessage.fileUpload.invalidMimeType = Unsupported/illegal mime type.
— form.user.errorMessage.fileUpload.fileTooBig = The file is too big.
Currently they are defined in the bundle info.magnolia.module.form.messages (in english and german only currently)

Comment by Christoph Meier [ 20/May/15 ]

list of allowed mime types - default configuration

Comment by Christoph Meier [ 20/May/15 ]

Commit is on branch MGNLFORM-254 (see http://goo.gl/5VXF8L).

Comment by Federico Grilli [ 20/May/15 ]

1) I'd rephrase this "Adds a TwinColSelectField to the formFile dialog to which allows to add a validator to the formFile field." -> "Add a TwinColSelectField to the formFile dialog which allows to specify a validator to the formFile field."
2) remove @param node @param controlName from javadoc of isFileFieldWithUploadedFile(..)
3) ExtendedValidator should probably override validateWithResult(String value) and throw an exception cause, looking at DefaultDataBinder, if it is an instance of ExtendedValidator you only call validateWithResult(value, controlName). I'd also state that clearly in the javadoc
3.1) I'd make ExtendedValidator an abstract class and wouldn't provide a default impl of validateWithResult(value, controlName) returning a valid result which might lead to weird and unexpected behavior if used carelessly
4) Some new files have copyright year 2014, e.g. ExtendedValidator

Comment by Christoph Meier [ 21/May/15 ]

Improved according to the review. Commits still on the same branch (see https://goo.gl/6FKjkW).

Comment by Tom Wespi [ 04/Jun/15 ]

Hello

any idea when 2.2.13 is going to be released?

Best Tom

Comment by Richard Gange [ 04/Jun/15 ]

Hey Tom-

I think this will be released with Magnolia 5.3.9, which is planned for Monday. I'll double check that though.

Cheers
Rich

Generated at Mon Feb 12 05:38:24 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.