How to set max_size in OneupUploaderBundle?

I want to set max_size files to load on 2 meters. I have the configuration below, but it still loads even 4 files ...

oneup_uploader:
    mappings:
        motors:
            frontend: blueimp 
            enable_progress: true 
            max_size: 2m

I saw this question # 92 , and it seems that there is an extra word in my config that is mappings. Is there something wrong?

thank

+4
source share
1 answer

I suggest an alternative way, since doing it like this did not work for me either. Do this using event listeners :

// Resources/services.yml
yourbundle.oneuploadvalidatorlistener:
    class: Amine\yourBundle\EventListener\oneupValidator
    arguments: [%your_own_defined_maxBytes%]
    tags:
       - { name: kernel.event_listener, event: oneup_uploader.validation, method: onValidate }

, , , , oneup_uploader.motors.validation( , )

EventListener:

namespace Amine\yourBundle\EventListener;
class oneupValidator {
private $max_size;

function __construct($max_size) {
   $this->max_size =$max_size;
}
function onValidate(ValidationEvent $event) {
    $file = $event->getFile();
// Do your logic here to check the size, and throw an exception if it does not validate 
    new ValidationException('error.max_size'); //Or your own error message
}
}

, .

+2

All Articles