Hi. I would like to pass this JavaScript callback

      init : {
        FilesAdded: function(up, files) {
          up.start();
        },
      }

using the '#plupload_settings'. Here is what I did, but it doesn't work and leads to JavaScript error. Is there any other way how to pass the callback to the init of Plupload?

  $form['gallery_upload'] = array(
    '#type' => 'plupload',
    '#title' => 'Some title',
    '#description' => 'Some desc',
    '#upload_validators' => array(
      'file_validate_extensions' => array('jpg jpeg gif png zip'),
    ),
    '#plupload_settings' => array(
      'runtimes' => 'html5,flash,html4',
      'chunk_size' => '1mb',
      'init' => 'FilesAdded: function(up, files){up.start();}',
    ),
  );

Comments

maxiorel’s picture

Title:Plupload init callbacks via #plupload_settings of the form element» Plupload automatic upload

OK, my workaround was to rewrite the parts of the module to use the jQuery UI version of Plupload and use the autostart option set to true. To bad the autostart doesn't work with pluploadqueue version.

slashrsm’s picture

What about solutions proposed here? http://stackoverflow.com/questions/8137229/plupload-automatically-start-...

It would be nice to have autoupload option on Form element, though. We should only find some reliable, friendly and non-hacky solution.

maxiorel’s picture

That would be nice, I saw it already. But I think it is not possible to push the

init : {
FilesAdded: function(up, files) {
up.start();
},
}

from creating the form on PHP side. Or I do not know how to do it at least, as I was asking in my initial post.

slashrsm’s picture

That's probbably true. We could add something like #autostart to form element and handle this setting in js on our own.

Have you tried to push this setting as an array, instead of a string?

maxiorel’s picture

Sure, I've tried. Without success.

slashrsm’s picture

StatusFileSize
new473 bytes

I tried this just to see if I can get autostart working, but it doesen't. Are you sure the code you proposed works?

maxiorel’s picture

I don't know already. I've ended up with rewriting the module to jQuery verison of Plupload and it works as excepted.

slashrsm’s picture

Can you share the code so we can check if we can incorporate your solution into this module?

maxiorel’s picture

Hi, sorry for late answer. My solution is very dirty without any config options. But works well and the upload starts as soon as the files are added to the Plupload area.

For the 7.x-1.3 version:
- plupload.module - changed the function a little bit. On the first lines, there are some jQuery UI call via drupal_add_library. The two rows with $library_path are changed.

<?php
function plupload_library() {
 
drupal_add_library('system', 'ui.core');
 
drupal_add_library('system', 'ui.widget');
 
drupal_add_library('system', 'ui.button');
 
drupal_add_library('system', 'ui.progressbar');
 
drupal_add_library('system', 'ui.sortable');
 
 
$library_path = _plupload_library_path();
 
$libraries['plupload'] = array(
   
'title' => 'Plupload',
   
'website' => 'http://www.plupload.com',
   
'version' => '1.5.1.1',
   
'js' => array(
     
// @todo - only add gears JS if gears is an enabled runtime.
      // $library_path . '/js/gears_init.js' => array(),
     
$library_path . '/js/plupload.full.js' => array(),     
     
$library_path . '/js/jquery.ui.plupload/jquery.ui.plupload.js' => array(),
     
0 => array(
       
'type' => 'setting',
       
'data' => array(
         
'plupload' => array(
           
// Element-specific settings get keyed by the element id (see
            // plupload_element_pre_render()), so put default settings in
            // '_default' (Drupal element ids do not have underscores, because
            // they have hyphens instead).
           
'_default' => array(
             
// @todo Provide a settings page for configuring these.
             
'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' => parse_size(ini_get('post_max_size')) . 'b',
             
'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'),
            ),
           
// The plupload.js integration file in the module folder can do
            // additional browser checking to remove unsupported runtimes.
            // This is in addition to what is done by the Plupload library.
           
'_requirements' => array(
             
'html5' => array(
               
// The Plupload library recognizes Firefox 3.5 as supporting
                // HTML 5, but Firefox 3.5 does not support the HTML 5
                // "multiple" attribute for file input controls. This makes the
                // html5 runtime much less appealing, so we treat all Firefox
                // versions less than 3.6 as ineligible for the html5 runtime.
               
'mozilla' => '1.9.2',
              ),
            ),
          ),
        ),
      ),
    ),
  );

  if (
module_exists('locale')) {
   
$module_path = drupal_get_path('module', 'plupload');
   
$libraries['plupload']['js'][$module_path . '/js/i18n.js'] = array('scope' => 'footer');
  }

  return
$libraries;
}
?>

Next, the plupload.js needs the change around the line 47:

      // Initialize Plupload for this element.
      //$this.pluploadQueue(pluploadSettings);
      $this.plupload(pluploadSettings);
mohit_aghera’s picture

@maxiorel
I am also using 7.x-1.3 version of the module.
If i am using HTML5 version then also it is not working. Is there any workaround for that ?
I changed as per your suggestion and cleared the cache too.. but it doesn't work for me..
Still i have to click upload button to upload the file.

I got this link from Plupload forums. http://www.plupload.com/punbb/viewtopic.php?pid=13150
Can we use the approach suggested by djdon11 user ?

mohit_aghera’s picture

@slashrsm
Did you got any solution for the auto upload ?
I am using html5 runtime, and the solution suggested by @maxiorel doesn't work for me.
I am trying to figure it out, let me know if you found something helpful.

slashrsm’s picture

Solution in #9 should work. We cannot commit this solution, though.

mohit_aghera’s picture

@Slashrsm
Can you please tell me which version of plupload you are using ?
Actually i am using the same code which you suggested me, but it is not working any more..
And i don't see any javascript or any other error too

slashrsm’s picture

Why do you think that mu Plupload version is important?

mohit_aghera’s picture

Probably there might be some issue from the plupload library version.. I am using 1.5.7

slashrsm’s picture

I am not having any problems with the patch, as I am not even using it. I am just saying that if we want to get something like this into official code it needs to be prepared in a way that will provide configurability and backward compatibility.

drupalina’s picture

I tried #9 and the entire plupload drag-n-drop box had converted to drupal's usual file upload interface. So it didn't work.

Can someone please post a working solution?!? In this day and age end-users expect not only a multiple upload but also auto-upload!!!

mohit_aghera’s picture

@drupalina Do you want to multiupload files with plupload only ? There is another solutions using Drupal form API you can try it out that. I used this solutions as i was not able to upload/multiupload files using plupload
http://mohitaghera.drupalgardens.com/content/multiple-file-upload-usind-...

drupalina’s picture

@mohit_rocks thanks for the link. What I want is not just multi-file upload, but also so that the "Start upload" button in plupload disappears and as soon as the files are selected the upload process should start immediately on its own! Automatically. My end-users are driving me crazy with stupid questions like "Oh, I uploaded the image files, but they are not showing up in my article" --and then it turns out that they forgot to press the "Start upload" button .... and it happens MOST of the time. It's as if people's IQ drops by 20% when they are on internet. So, this auto-upload is really a critical functionality. The question is how to get it to work in plupload?

drupalina’s picture

[drupal.org repeated the same comment above]

drupalina’s picture

[drupal.org repeated the same comment above]

mohit_aghera’s picture

@drupalina,
I got your point, actually i also faced this kind of situation, but none of the above solutions worked for me.
Are you using CCK in your form or created form programmatically..
I was using plupload in custom form i.e. form created programmatically rather than CCK forms
What i did was to disable ""Start upload" button and manage the file upload in form submit handler. When I submit the form I managed uploading files manually.

drupalina’s picture

@mohit_rocks (sorry for the duplicate posts. Drupal.org is misbehaving)
Yes, my image field is done through CCK (built into D7). Do you know how to achieve this Auto-upload functionality for CCK plupload fields? Thanks.

vladan.me’s picture

StatusFileSize
new598 bytes

I believe this would work, althought not configurable, just as a temporary solution... Can you please try it so I can try making it better?

----------------
Edit: Paths in patch might not be configured right, sorry

vladan.me’s picture

StatusFileSize
new458 bytes

Second try

vladan.me’s picture

StatusFileSize
new630 bytes

i've got something, just not sure if is "pretty" solution. Please revise...
This would make images autoupload and autosubmit form that you pass (through form id).
I am making assumption that images are processed in some custom form?

Usage would be something like:

$options['plupload_settings'] =  array(
    'autostart' => '#my-form-upload-id',
    // other options
    'runtimes' => 'html5',
    'chunk_size' => '1mb',
  );
drupalina’s picture

I manually applied the patch in #26 ,cleared the cache. Nothing changed- we still need to click the "Start upload" button.
I didn't apply the $options code because I didn't know where to put it ???

vladan.me’s picture

In place where you define your plupload as a type - as in first post of this issue, for example

  $form['gallery_upload'] = array(
    '#type' => 'plupload',
    '#title' => 'Some title',
    '#description' => 'Some desc',
    '#upload_validators' => array(
      'file_validate_extensions' => array('jpg jpeg gif png zip'),
    ),
    '#plupload_settings' => array(
      'runtimes' => 'html5,flash,html4',
      'chunk_size' => '1mb',
      'autostart' => '#my-form-upload-id',
    ),
  );

You just need to enter exact id of your form which will process images uploaded... Maybe there's more obvious way to do it but I am not aware of it right now.

drupalina’s picture

OK - thanks. But I'm not a coder.
Please tell me:
1) in which file should I add this "$options['plupload_settings'] = array(" code? is it plupload.module ? or some kind of .inc file? and on which line?
2) what do I need to put instead of "gallery_upload" and "#my-form-upload-id" ??? How do I find out what these variables are on my own installation?

Thanks!

vladan.me’s picture

@drupalina
Are you sure you are using this module and not https://drupal.org/project/plup ?
Sorry to ask that question but I am kind of confused with your questions and I read at plup module:
" It provides a field widget for image field that allow user to upload multiple images at once using Plupload library."
I am not aware that this module is able to integrate as field widget for image field, or I am missing something big?

drupalina’s picture

@vladan.me yes, my Plup module is disabled. And yes you are missing something :) because you can use this Plupload integration module to upload multiple images . Watch this screencast http://youtu.be/lKfDIWdWQ5c

Now back to my 2 questions in #29 :
1) in which file should I add this "$options['plupload_settings'] = array(" code? is it plupload.module ? or some kind of .inc file? and on which line?
2) what do I need to put instead of "gallery_upload" and "#my-form-upload-id" ??? How do I find out what these variables are on my own installation?

vladan.me’s picture

Ah, ok, I see... I have checked those modules and found out that they are using their custom version of plupload... Pretty much independent from this since it's overwriting plupload.js. What I am trying to say, that patch I wrote for this module doesn't affect your case.
Anyway, you should better contact maintainer of filefield_sources_plupload to see if he can help you with it.
Cheers

drupalina’s picture

Thanks @vladan.me - I will definitely take this up with filefield_source_upload .

vladan.me’s picture

Status:Active» Needs review

Can maintainer please review patch submitted in #26? Thanks

slashrsm’s picture

Status:Needs review» Needs work

It looks nice. I'd just like to see some info about this in README.txt. People will not know about this new feature if we don't document it.

slashrsm’s picture

Status:Needs work» Needs review
StatusFileSize
new4.17 KB

Here is my proposal:

1. Some docs added to README.txt.
2. I think that we should make automatic submit optional. Added another setting that handles this.
3. Auto-submit should check if there is #submit_element and use that specific element to submit if it does.
4. No need to add form ID, since the form element can be found in JS.

vladan.me’s picture

There are two problems here that may occur:
1) if you want to use autosubmit without autoupload by default you won't get uploaded images. You will have to make custom callback to upload images.
2) If you want to use autoupload without autosubmit by default you will have "locked" plupload form without being able to click add or start again since after upload it will overwrite it with "Uploaded" text. Again, you will have to make custom callback to submit images.

slashrsm’s picture

1) if you want to use autosubmit without autoupload by default you won't get uploaded images. You will have to make custom callback to upload images.

My idea was to only support autosubmit together with autoupload. #36 should work that way.

2) If you want to use autoupload without autosubmit by default you will have "locked" plupload form without being able to click add or start again since after upload it will overwrite it with "Uploaded" text. Again, you will have to make custom callback to submit images.

Submit is done via Drupal native form and PLupload should not interfere with that by default. I way playing with this on File entity upload form and it worked OK (i.e. autoupload uploaded files and I normally submitted form by pressing "Next" when it was done).

vladan.me’s picture

Submit is done via Drupal native form and PLupload should not interfere with that by default. I way playing with this on File entity upload form and it worked OK (i.e. autoupload uploaded files and I normally submitted form by pressing "Next" when it was done).

Yes, that is true, I am just pointing out that if this option is enabled you will not be able to upload more files with plupload in that form, but ok, that is on user to decide if he wants this option.

slashrsm’s picture

Status:Needs review» Closed (duplicate)

That's true. Maybe we should express that in README.txt docs once patch is ready.

I'll close this as we're effectively going to do most of coding in #2065927: Plupload events support?.