1

我在 mvc 站点中使用 plupload,并希望在选择单个文件后立即上传。我将上传控件的自动启动设置为 true,但这不会激活上传。我还尝试调用uploader.start();上传者的“filesadded”委托,但这仅适用于我尝试上传的第二个文件。我正在使用没有 UI 小部件的 plupload 1.4.3.2。这是我的代码:

var uploader = new plupload.Uploader({
    runtimes: 'gears,html5,flash,silverlight,browserplus',
    browse_button: 'pickfiles',    
    autostart : true,    
    max_file_size: '10mb',
    url: '/Event/Upload',
    resize: { width: 320, height: 240, quality: 90 },
    flash_swf_url: '/Scripts/pl/plupload.flash.swf',
    silverlight_xap_url: '/Scripts/pl/plupload.silverlight.xap',
    filters: [
    { title: "Image files", extensions: "jpg,gif,png" },
    { title: "Zip files", extensions: "zip" }
]
});
uploader.bind('Init', function (up, params) {
    $('#filelist')[0].innerHTML = "<div>Current runtime: " + params.runtime + "</div>";
});
uploader.bind('Error', function (up, err) {
    $('#filelist').append("<div>Error: " + err.code +
        ", Message: " + err.message +
        (err.file ? ", File: " + err.file.name : "") +
        "</div>"
    );

});
uploader.bind('FilesAdded', function (up, files) {
    for (var i in files) {
        $('#filelist')[0].innerHTML += '<div id="' + files[i].id + '">' + files[i].name + ' (' + plupload.formatSize(files[i].size) + ') <b></b></div>';
    }
    //uploader.start();
});
$('#uploadfiles').click(function (e) {
    uploader.start();
    e.preventDefault();
});

uploader.bind('UploadProgress', function (up, file) {
    $('#' + file.id)[0].getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
});

uploader.init();;
4

3 回答 3

6

在您的 FilesAdded 事件中更改 uploader.start(); 到 setTimeout('uploader.start()', 100);

于 2011-06-28T21:22:42.060 回答
1

“确保在初始化之后绑定它,因为它绑定了默认处理程序。”

更多信息

(我知道为时已晚,但我仍然喜欢这个解决方案)

于 2012-01-15T15:25:32.700 回答
0

确切地!只需按该订单订购命令:

uploader.init();
uploader.bind('FilesAdded', function(up, files) {
    ...
    uploader.start();
});
于 2012-03-07T08:51:11.087 回答