You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
maxSize
type: mixed
If set, the size of the underlying file must be below this file size in order to be valid. The size of the file can be given in one of the following formats:
bytes: To specify the maxSize in bytes, pass a value that is entirely numeric (e.g. 4096);
kilobytes: To specify the maxSize in kilobytes, pass a number and suffix it with a lowercase "k" (e.g. 200k);
megabytes: To specify the maxSize in megabytes, pass a number and suffix it with a capital "M" (e.g. 4M).
valdiation.yml:
Cmf\FileBundle\Entity\Image:
properties:
name:
- NotBlank: ~
- MinLength: 3
file:
- File:
maxSize: 500M <<<
mimeTypes: [image/jpg, image/jpeg, image/png]
mimeTypesMessage: This is not an image.
Response when uploading 3M file:
{"children":{"name":[],"file":{"errors":["The file is too large. Allowed maximum size is 500M bytes."]}}}
Notice it says "500M bytes", according to the doc, capital M is supposed to be for megabytes.
500k doesn't work either, as a matter of fact it always goes by bytes no matter what you specify, as long as its higher than the upload_max_filesize set in php.ini.
Quick fix:
Set upload_max_filesize to something ridiculous like 500M(not recommended, but allows the validation to work).
Solution:
I'm sadly not capable of solving this, hurray for open source though =)
In short, if the validation value is higher than the one that is set in php.ini, the validation doesn't work at all for anything else than bytes, no matter if you specify "k" or "M", and the error message also reflects this behaviour.
The text was updated successfully, but these errors were encountered:
This PR was merged into the 2.1 branch.
Commits
-------
7216cb0 [Validator] fix showing wrong max file size for upload errors
Discussion
----------
[Validator] fix showing wrong max file size for upload errors
this was because the maxSize option wasn't parsed correctly and simple string comparision could lead to wrong results, e.g. 200 > 1000M
| Q | A
| ------------- | ---
| Bug fix? | [yes]
| New feature? | [no]
| BC breaks? | [no]
| Deprecations? | [no]
| Tests pass? | [yes|]
| Fixed tickets | [#6441,#5551]
| License | MIT
Will apply cleanly to 2.2
http://symfony.com/doc/current/reference/constraints/File.html
maxSize
type: mixed
If set, the size of the underlying file must be below this file size in order to be valid. The size of the file can be given in one of the following formats:
bytes: To specify the maxSize in bytes, pass a value that is entirely numeric (e.g. 4096);
kilobytes: To specify the maxSize in kilobytes, pass a number and suffix it with a lowercase "k" (e.g. 200k);
megabytes: To specify the maxSize in megabytes, pass a number and suffix it with a capital "M" (e.g. 4M).
valdiation.yml:
Cmf\FileBundle\Entity\Image:
properties:
name:
- NotBlank: ~
- MinLength: 3
file:
- File:
maxSize: 500M <<<
mimeTypes: [image/jpg, image/jpeg, image/png]
mimeTypesMessage: This is not an image.
Response when uploading 3M file:
{"children":{"name":[],"file":{"errors":["The file is too large. Allowed maximum size is 500M bytes."]}}}
Notice it says "500M bytes", according to the doc, capital M is supposed to be for megabytes.
500k doesn't work either, as a matter of fact it always goes by bytes no matter what you specify, as long as its higher than the upload_max_filesize set in php.ini.
Quick fix:
Set upload_max_filesize to something ridiculous like 500M(not recommended, but allows the validation to work).
Solution:
I'm sadly not capable of solving this, hurray for open source though =)
In short, if the validation value is higher than the one that is set in php.ini, the validation doesn't work at all for anything else than bytes, no matter if you specify "k" or "M", and the error message also reflects this behaviour.
The text was updated successfully, but these errors were encountered: