我在 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();;