4

I want to set the max_size of files to be uploaded to 2m. I have the config below but it is still uploading even 4m files...

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

I have seen that issue #92 and it seems that there is an extra word in my config which mappings. Is there any thing wrong??

Thanks

Amine Jallouli
  • 3,919
  • 8
  • 36
  • 73
  • Did you try looking for this parameter in web server configuration? I guess a file like httpd.conf (for Apache HTTP server) may contain such directive.hope it helps – Adib Aroui Nov 19 '14 at 20:47
  • I am able to set the max size in the php.ini. I am wondering if it is possible to do that also in the config of the OneupUploaderBundle. This is the goal of the question... – Amine Jallouli Nov 20 '14 at 06:19
  • did you tried the value -1 as indicated in configuration reference? – Adib Aroui Nov 21 '14 at 14:06
  • can you give me the link please... – Amine Jallouli Nov 22 '14 at 16:00
  • https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/configuration_reference.md. If I understand well, this will allow only use of php.ini value. please correct me if i am wrong i dont have big experience – Adib Aroui Nov 24 '14 at 13:26

1 Answers1

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.

Martin Fasani
  • 825
  • 7
  • 20