In my case I need to separate files selection and files upload, so I commented the call to uploadNextInQueue() in dialogComplete().
The actual upload is fired by another button which onclick calls uploadNextInQueue().
What I want is automatically submit the form once all files have been uploaded.
I tried placing the following code at the end of uploadSuccess():

if (ref.swfu.getStats().files_queued === 0) {
  $('#edit-submit').click();
}

The form is being submitted but the uploaded files are not being saved in $node.
I think that something's need to be accomplished before submitting the form.
Which is the right place/moment to fire the submit? Or, which is the better solution to achieve this behavior?

Thanks,
bob

Comments

bob_hirnlego’s picture

Title: Submit after all files have been uploaded » Upload upon form submission

Sorry to bother, but after a few more hours I still don't get it and it's a blocking issue.
Maybe the post was a bit convoluted... I'll try to reformulate my needs.

I need the actual files upload to happen when submitting the form. To achieve this I need to break the default sequence "file selection - file upload", and let the submit button trigger the upload (or vice-versa).

Could you suggest me the proper way to do this?

Thanks,
bob

skilip’s picture

Did you use updateStack() after each upload? This function appends the data of the uploaded file to an hidden form field. After the form is submitted, the value of the hidden field is passed to the node object.

bob_hirnlego’s picture

No, the only thing I did was commenting uploadNextInQueue() in dialogComplete() for disabling the automatic upload after file selection.
The idea was to let the user click on a submit button that would call uploadNextInQueue(), started the upload, and then submitted the form.
Is this the right approach?

Thank you,
bob

skilip’s picture

You only need to be sure the hidden form element is updated after each upload.

bob_hirnlego’s picture

Tracing the upload process, I discovered that finally the method ref.addEventHandlers() with argument 'file_added' was called.
I could easily consider this as the last step in the upload process and fire the form submit from here, but I can't actually be sure that ALL the files have been added.
I'm really missing a callback or something that tells me "Ok, all the files in queue have been processed, no more is to be done here".
This either as a javascript callback or a Drupal one.

skilip’s picture

You can try to change the upload complete callback in the SWFUpload configuration. This is currently ref.uploadComplete(). Check the function _swfupload_swfupload().

skilip’s picture

Status: Active » Closed (fixed)