Unable to pass additional parameters in plupload

杀马特。学长 韩版系。学妹 提交于 2019-12-17 07:51:31

问题


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


回答1:


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




回答2:


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)



来源:https://stackoverflow.com/questions/13367897/unable-to-pass-additional-parameters-in-plupload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!