Topic: How to dynamically change multipart_params?

Is it possible to dynamically change multipart_params?

I'm looking for something like:
$('#uploader').settings('multipart_params', { 'var1': 'val1', 'var2': 'val2' });

I need to change the multipart_params AFTER plupload has been initialized.

Is there other ways to dynamically pass variables to the url script (eg. upload.php)? That way I could modify the form data before submitting it. I've tried putting hidden fields in the form, but that doesn't seem to work.

Any help is highly appreciated!

Re: How to dynamically change multipart_params?

Any ideas? smile

Re: How to dynamically change multipart_params?

servous wrote:

Is it possible to dynamically change multipart_params?

Hi servous,

Yes, it is possible.  Just write to the settings property on the Uploader object.  Runtimes will automatically pick up the new settings, so subsequent uploads will use the new multipart_params.

For example if you are using the upload queue plugin, something like this would do it:

$('#uploader').pluploadQueue().settings.multipart_params = { var1: 'val1', var2: 'val2'};

The event listeners generally pass an Uploader param which can also be used to directly access and manipulate the settings property.

Hope that helps.

Re: How to dynamically change multipart_params?

var uploader = $('#uploader').plupload('getUploader');
uploader.settings.multipart_params.type = $("#type").val();
Where "type" was the param i was wanting to set dynamically.

worked for me.

Re: How to dynamically change multipart_params?

I added it succ. for example, I want to add a <input type='text' id='title'/> and a <textarea id='comment'></textarea> within the form, the steps:

(1) in $("#uploader").pluploadQueue({}), add:
multipart_params: { 'title': $('#title').val(),'comment': $('#comment').val() },

(2) add the following right after $("#uploader").pluploadQueue({}):
    var uploader = $('#uploader').pluploadQueue();
    uploader.bind('FilesAdded', function(up, files) {
        uploader.settings.multipart_params.title = $("#title").val();
        uploader.settings.multipart_params.comment = $("#comment").val();       
    });

they work fine.

Re: How to dynamically change multipart_params?

IMHO, the better solution is to use event  'BeforeUpload' instead of 'FilesAdded' :
...
uploader.bind('BeforeUpload', function(up, files) {
...

7 (edited by agrublev 2012-08-25 19:25:06)

Re: How to dynamically change multipart_params?

aaaaaand done smile

i use the awesome file id which I have cleverly appended to an element in my html to call that element and collect specific data for that file. The rest is history. Hope this helps others!

uploader.bind("BeforeUpload", function(up,file) {
            console.log(file.id);
            var $th = $("#" + file.id);
            //console.log(file);
            var f_type = $th.find(".type").val();
            var f_description = $th.find(".description").val();
            console.log("type = " + f_type + " and the desc = " + f_description);
            uploader.settings.multipart_params = {container_id: $("#container_id").val(),type: f_type, description: f_description};
        });