我在mvc站點中使用plupload,並希望在選擇它時立即上傳單個文件。我將上傳器控件的自動啓動設置爲true,但這不會激活上傳。我也嘗試在上傳器的'filesadded'委託中調用uploader.start();
,但這隻適用於我嘗試上傳的第二個文件。我正在使用沒有UI小部件的plupload 1.4.3.2。這裏是我的代碼:自動啓動選項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();;
我設法得到它的工作通過添加調用從FilesAdded方法就像一個超時up.start功能:的setTimeout(函數(){ up.start(); },1000); – Gluip 2011-06-03 12:50:43