I'd like to make a small request regarding only a specific piece of the max filesize issue previously discussed at #1060448: Support for max upload size and resize parameters.

I noticed that the plupload js options include max_file_size for client-side validation. I took a look at how plupload_element_pre_render() checks #upload_validators and if file_validate_extensions() is included, the value is passed into the js settings for that form element. I think it'd be helpful to similarly check #upload_validators for file_validate_size() and pass the limit value to the max_file_size js setting.

This way, modules generating/altering forms to use the plupload form element can easily specify a max file size that gets validated both server- and client-side. This would not introduce any additional configuration nor is it dependent on any field's settings.

Comments

slashrsm’s picture

Sure. It sounds very nice feature. We should definitely add that.

artematem’s picture

Issue summary: View changes

Workaround:

/**
 * Implements hook_library_alter().
 */
function MYMODULE_library_alter(&$libraries, $module) {
  if ($module == 'plupload' && isset($libraries['plupload'])) {
    if (current_path() == 'media/browser') {
      $params = media_get_browser_params();
      if (isset($params['max_filesize'])) {
        $libraries['plupload']['js'][0]['data']['plupload']['_default']['max_file_size'] = $params['max_filesize'];
      }
    }
  }
}

Looking forward for better implementation of file size validation)