2

I'm using plupload, the JQuery UI implementation. I'm trying to pass additional parameters to the server, but I can't make it work. It should be pretty straightforward, the parameters are already set when the function is executed, so that should not be a problem. I've tried this:

function GetPlUploader(m)
{
$("#divOpplaster").plupload(
{
    // General settings
    runtimes: 'flash,html5,silverlight',
    url: 'upload.php',
    max_file_size: '10mb',
    chunk_size: '1mb',
    unique_names: true,
    multipart: true,
    multipart_params: [
    {
        'ordre': ordreibruk,
        'mode': m}
    ],

    // Specify what files to browse for
    filters: [
    {
        title: "Bildefiler",
        extensions: "jpg,gif,png,bmp"}
    ],

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

    // Silverlight settings
    silverlight_xap_url: 'plupload/js/plupload.silverlight.xap',

    init: {
        FileUploaded: function(up, file, info)
        {
            // Called when a file has finished uploading
            console.log('[FileUploaded] File:', file, "Info:", info);
        }
    }
});

console.log("Ordre: " + ordreibruk + ". Mode: " + m)

$("#divOpplaster").dialog(
{
    autoOpen: false,
    width: 650,
    show: "fade",
    hide: "fade"
})

$("#divOpplaster").dialog("open")

// Client side form validation
$('form').submit(function(e)
{
    var uploader = $('#uploader').plupload('getUploader');

    // Files in queue upload them first
    if (uploader.files.length > 0)
    {
        // When all files are uploaded submit form
        uploader.bind('StateChanged', function()
        {
            if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed))
            {
                $('form')[0].submit();
            }
        });

        uploader.start();
    }
    else
    alert('Du må velge minst én fil for opplasting.');

    return false;
});
}

I've also tried to add this in the $('form').submit section:

uploader.bind('BeforeUpload', function(up)
    {
    up.settings.multipart_params =
    {
        'ordre': ordreibruk,
        'mode': m
    };

});

But to no avail.

I'm sure I'm overlooking something really simple, but what?

Kind regards, Anders

aanders77
  • 620
  • 8
  • 22

2 Answers2

4

I must confess I use to put my parameters as query string parameters in the url :

  • during init : url: '/upload.aspx?id='+Id,
  • or later : upldr.settings.url = upldr.settings.url + '&token=' + myToken;

It works fine. Hope this will help

jbl
  • 15,179
  • 3
  • 34
  • 101
  • jbl, thanks for your reply. I would prefer to do it "the right way", but I'm going to start out with your solution and hopefully someone can give us both a pointer in the right direction later on :) – aanders77 Nov 14 '12 at 19:17
  • @jbl can i do this with resize parameter....?? i mean resize as url additional...? – Sagar Naliyapara Aug 08 '15 at 10:24
  • @SagarNaliyapara I guess you can add any parameter that fits your needs – jbl Aug 10 '15 at 16:03
0

Had the same issue. Stumbled upon this snippet that can easily translated into coffescript as well that works for my project. Allows you to pass multipart params after initialization (like in the case a field can change before the upload is hit)

var myUploader = $('#uploader').plupload('getUploader');
myUploader.bind('BeforeUpload', function(up, file) {
    up.settings.multipart_params = {path : $("#path").val()};
});

Call it after you do your normal initialize and setup of $("#divOpplaster").plupload(...) (and set your ID appropriately to your uploader field, of course)

TechImp
  • 131
  • 9