4

我想将要上传的文件的 max_size 设置为 2m。我有下面的配置,但它仍在上传甚至 4m 的文件......

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

我已经看到那个问题#92并且我的配置中似乎有一个额外的单词mappings。有什么问题吗??

谢谢

4

1 回答 1

2

I will suggest an alternative way, since doing it like this didn't worked for me too. Do it with 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 }

Note that if you have multiple uploaders and want to target one of them, in the event you can add it in the middle like oneup_uploader.motors.validation (I'm quite sure worked for me this way )

And then just create that EventListener class:

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
}
}

This is just a theoretical solution try to adapt it to your needs.

于 2014-11-19T08:36:45.497 回答