What's wrong with my plupload implementation?


For reasons that are out of scope here I should not send packets over 32 MB, so my php.ini looks like this:

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 500M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 32M

I know plupload can do this, so I “only” needed to integrate it with Drupal. For this I installed Plupload integration module. Thanks to Clive I found this bug report:

Right now you need to spesify a max file size larger than the max post size as plupload is stil honoring the setting.

I’m not particularly happy with upload_max_filesize = 500M but I guess for now I can live and work with it.

I tried custom code first:

  'DownloadFile' => array(
    //'#type' => 'managed_file',
    '#type' => 'plupload',
    '#title' => t("Download"),
    '#title_display' => 'invisible',

    '#upload_validators' => array(
      'file_validate_extensions' => array(),
      'file_validate_size' => array(variable_get('my_max_file_size', 300 * 1024 * 1024)),
    ),
    '#upload_location' => 'public://mymodule/download',
    '#default_value' => $item->fid,
    '#required' => TRUE,
    '#plupload_settings' => array(
      'runtimes' => 'html5',
      'chunk_size' => '10mb',
    ),
  ),

It was showing 300MB under the Form API field all right. Sadly, everything over 20MB gave me:

Error: File too large: Some_182MB_file.zip

So I thought I’m doing something wrong and decided to try ready-made solution. I went for FileField Sources Plupload – I see 32 MB on the node add form, but 182 MB file uploaded all right.

So what’s wrong with my implementation? I practically copied example from official documentation so I would expect it to work.

One Response to “What's wrong with my plupload implementation?”

  1. Mołot says:

    When using Plupload integration module in custom code, you need to set up size twice. Preferably to the same value. First place you do it is the usual:

    '#upload_validators' => array(
      'file_validate_size' => array(variable_get('my_max_file_size', 300 * 1024 * 1024)),
    ),
    

    This handles display and post-upload verification.

    Second place is #plupload_settings:

    '#plupload_settings' => array(
      'runtimes' => 'html5',
      'chunk_size' => '10mb',
      'max_file_size' => variable_get('my_max_file_size', 300 * 1024 * 1024) . 'b',
    ),
    

    This is what actually goes to the plupload JavaScript.

Leave a Reply

Question and Answer is proudly powered by WordPress.
Theme "The Fundamentals of Graphic Design" by Arjuna
Icons by FamFamFam