无法在plupload中传递其他参数

时间:2012-11-13 20:05:19

标签: jquery-ui parameter-passing plupload

我正在使用plupload,即JQuery UI实现。我正在尝试将其他参数传递给服务器,但我无法使其工作。它应该非常简单,在执行函数时已经设置了参数,因此这不应该是一个问题。我试过这个:

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;
});
}

我也尝试在$('form')中添加这个.stats section:

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

});

但无济于事。

我确定我忽略了一些非常简单的东西,但是什么呢?

亲切的问候, 安德斯

2 个答案:

答案 0 :(得分:4)

我必须承认我用来将我的参数作为查询字符串参数放在url:

  • 在init期间:url: '/upload.aspx?id='+Id,
  • 或更高版本:upldr.settings.url = upldr.settings.url + '&token=' + myToken;

工作正常。 希望这会有所帮助

答案 1 :(得分:0)

有同样的问题。偶然发现这个片段很容易翻译成coffescript,也适用于我的项目。允许您在初始化后传递多部分参数(例如,在上传命中之前字段可以更改)

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

在你正常初始化和设置$(" #divOpplaster")之后调用它.plupload(...)(当然,将你的ID设置为你的上传者字段)