user2091928
user2091928

Reputation: 63

plupload dynamic multi params

I am using plupload to allow users to upload files. I am passing two multi params with plupload. The first parameter is dynamically set when the page loads. The other is set when the user selects from a select menu.

The second parameter is blank when the page loads and I don't know how to pass it to plupload after the user makes a choice.

If I add the plupload code to the change function it works but I don't want that because plupload is not visible until the user makes a choice.

I hope someone can help me.

here is my code:

    $("#uType").change(function(){
        var upType = $('#uType').val();
        $("#type").val(this.value); 
    });

    var uploader = $("#uploader").plupload({
        // General settings
        runtimes : 'html5,flash,silverlight,html4',
        url : "/wp-content/plugins/tyhp-filemaker/tyhp-youth-upload.php",

        // Maximum file size
        max_file_size : '2mb',

        chunk_size: '1mb',

        // Resize images on clientside if we can
        resize : {
        width : 200, 
        height : 200, 
        quality : 90,
        crop: true // crop to exact dimensions
        },

        multipart_params: {'type': $('#type').val(), 'account' : $('#AccountUpload').val()},

        // Specify what files to browse for
        filters : [
            {title : "Image files", extensions : "jpg,gif,png"},
            {title : "Zip files", extensions : "zip,avi"}
        ],

        // Rename files by clicking on their titles
        rename: true,

        // Sort files
        sortable: true,

        // Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
        dragdrop: true,

        // Views to activate
        views: {
             list: true,
             thumbs: true, // Show thumbs
             active: 'thumbs'
         }

         // Flash settings
         flash_swf_url : '/plupload/js/Moxie.swf',

        // Silverlight settings
        silverlight_xap_url : '/plupload/js/Moxie.xap'
      });

Upvotes: 1

Views: 1129

Answers (3)

Saranga Mapalagama
Saranga Mapalagama

Reputation: 81

You can use BeforeUpload option to add multipart params

uploader.bind('BeforeUpload',  function(up, file) {
    uploader.settings.multipart_params.type = $('#type').val();
    uploader.settings.multipart_params.account = $('#AccountUpload').val();
    console.log(file);
});

Upvotes: 0

McAuley
McAuley

Reputation: 424

Try it by removing the 'quote' on your multipart_params variable names, like this:

multipart_params: { type: $('#type').val(), account : $('#AccountUpload').val() }

I know -- the examples use the quotes. And they actually worked in other versions. But unfortunately, for you, me, and many others, this product's documentation leaves a lot to be desired. I've had to spend far too many hours debugging it just to see what it is really doing. Even on the 'latest' version. I don't think anyone is maintaining it anymore.

Upvotes: 0

user2091928
user2091928

Reputation: 63

I have found a solution to my problem.

Here is how you connect to the existing plupload instance and set the multi params based on an change event from a select menu:

$("#uType").change(function(){
    var upType = $('#uType').val();
    $("#type").val(this.value); 
    var uploader = $('#uploader').plupload('getUploader');
    uploader.settings.multipart_params.type = $("#type").val();
    uploader.settings.multipart_params.account = $('#AccountUpload').val();
});

Upvotes: 2

Related Questions