I'm not sure if this is a bug in the code or in the documentation.

The README states:

- #plupload_settings - array of settings, that will be passed to Plupload library.
  See: http://www.plupload.com/documentation.php
  Defaults to:
  '#plupload_settings' => array(
    'runtimes' => 'html5,flash,html4',
    'url' => url('plupload-handle-uploads', array('query' => array('plupload_token' => drupal_get_token('plupload-handle-uploads')))),
    'max_file_size' => file_upload_max_size() . 'b',
    'chunk_size' => '1mb',
    'unique_names' => TRUE,
    'flash_swf_url' => file_create_url($library_path . '/js/plupload.flash.swf'),
    'silverlight_xap_url' => file_create_url($library_path . '/js/plupload.silverlight.xap'),
  ),

This implies that these defaults will be set by the plupload module. However, the plupload module is not setting any of these defaults.

I am using plupload with the media / file_entity integration being worked on here: #951004: Allow selecting of multiple media items for a multi value media field in the same dialog, specifically using the patch to media in comment #106.

This patch to media is not implementing hook_entity_info_alter() to set #plupload_settings for type = 'plupload'. Since it's not setting any defaults for #plupload_settings, and plupload is also not setting any defaults, no defaults are being set. Due to the lack of defaults for #plupload_settings, file upload chunking isnot actually happening.

From what I can tell it should be the responsibility of plupload module to set these defaults. As such, I have provided a patch to set these defaults. If I am incorrect and it is not the responsibility of plupload module to set these defaults (due to its status as a developer api module for other modules to make use of), then the README should be changed to make it explicitly clear that no defaults are being set for this element property.

Patch to follow.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dtarc’s picture

Here's the patch:

slashrsm’s picture

Status: Active » Postponed (maintainer needs more info)

Defaults are set by plupload_library() and then handeled in plupload.js Is there anything that I'm missing here?

ergophobe’s picture

dtarc’s picture

Status: Postponed (maintainer needs more info) » Needs review

Ok, that was my mistake. I was looking in plupload_element_pre_render() and expecting to see a #plupload_settings property with defaults filled in on the $element object. There were none. However, it doesn't matter, as you are right, that defaults are indeed being set by plupload_library().

However, there is still an issue, probably with the documentation, maybe with the code.

The documentation (README.txt) lists the default chunk_size as 1mb:

    'chunk_size' => '1mb',

However, in plupload, the default chunk_size is actually being taken from php's post_max_size var:

              'chunk_size' => parse_size(ini_get('post_max_size')) . 'b',

The reason that we weren't seeing chunking happening on file uploads is because we've got our post_max_size cranked up. We had it set so high so that we could accommodate large file uploads (as we are currently using D7 core file upload widget as well as media's file upload widget). For regular file uploads, allowable file size is constrained to that post_max_size var. I don't think it's all that uncommon for drupal sites to have a high value for that variable, especially for sites needing to accommodate large file uploads.

So perhaps the issue is the documentation, and rather than giving the default value for chunk_size as 1mb, the README should make clear that the default value is being taken from post_max_size. That would certainly be helpful to people making use of plupload.

Personally I think the default value should not be taken from post_max_size as it's very likely to be too big for the chunk size drupal site builders are looking for. I'd set it to 16mb or 32 mb. Perhaps it would better be set to the minimum of post_max_size and one of these (16mb or 32mb), because if post_max_size is small then having a higher chunk_size will break uploads. PHP's default value for post_max_size is 8mb, so maybe that's the safest size to use.

In any case, there is a discrepancy between the documented default for chunk_size and the actual default, and this discrepancy can break file upload chunking and sometimes file uploads in common site configurations. Either the documentation or the code should be changed.

dtarc’s picture

This is how we are overriding the plupload module's default value for chunk_size:

/**
 * Implementation of hook_library_alter()
 */
function mymodule_library_alter(&$libraries, $module) {
  if ('plupload' == $module && isset($libraries['plupload'])) {
    if (isset($libraries['plupload']['js'][0]['data']['plupload']['_default'])) {
      $libraries['plupload']['js'][0]['data']['plupload']['_default']['chunk_size'] = '16mb';
    }
  }
}
dtarc’s picture

Title: No defaults are being set for #plupload_settings » Documented default for chunk_size does not match value in code
Component: Code » Documentation
dtarc’s picture

Updated title and component to more appropriate values.

slashrsm’s picture

Category: Bug report » Task
Priority: Normal » Minor
Status: Needs review » Needs work

Re #5: you should override via #plupload_settings.

Yes, README.txt would probably need an update.

budalokko’s picture

Status: Needs work » Fixed

Actually README.txt was already modified to match value in code on 7.x-2.x branch at #2098555: Make compatible with plupload version 2.1.9 so closing the issue.

README.txt also documents the way to change this value via #plupload_settings.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.