var uploader = new plupload.Uploader({
runtimes : 'silverlight',
browse_button : 'pickfiles',
container : 'container',
max_file_size : '20mb',
url:"/"+CONTEXT_NAME+"/importFromExcelAction.uploadExcelFile.do",
multipart: true,
chunk_size : '10mb',//把大文件分割
unique_names : true,
urlstream_upload : true,
multiple_queues : false,
filters : [{title : "Excel文件", extensions : "xls,xlsx"}],
silverlight_xap_url : '/'+CONTEXT_NAME+'/modules/common/attach/plupload/script/plupload.silverlight.xap'
});
uploader.bind("Init",function(up,params){
$J('#filelist').html("
Current runtime: " + params.runtime + "
");
});
uploader.bind("FilesAdded",function(up,files){
$J.each(files, function(i, file) {
$J('#filelist').append(
'
' +
file.name + ' (' + plupload.formatSize(file.size) + ') ' +
'
');
});
up.refresh();
});
$J("#uploadfiles").click(function(e){
uploader.start();
e.preventDefault();
})
uploader.bind('UploadProgress', function(up, file) {
$J('#' + file.id + " b").html(file.percent + "%");
});
uploader.bind('Error', function(up, err) {
$J('#filelist').append("
Error: " + err.code +
", Message: " + err.message +
(err.file ? ", File: " + err.file.name : "") +
"
"
);
up.refresh(); // Reposition Flash/Silverlight
});
uploader.bind('FileUploaded', function(up, file) {
$J('#' + file.id + " b").html("100%");
$J('#filelist').append("上传成功...
");
$J('#filelist').append("开始处理Excel数据...
");
var request = $J.ajax({
url:'/'+CONTEXT_NAME+'/importFromExcelAction.importExcel.do',
type:"post",
data:{
template:$J("#selectTemplate").val(),
fileName:file.name
}
});
// 定时获取导入状态
var task = window.setInterval("getImportStatus()",5000);
request.done(function(data){
$J('#filelist').append("success:"+data.success+",msg:"+data.msg+"
");
window.clearInterval(task);
});
request.fail(function(jqXHR, textStatus){
$J('#filelist').append("请求处理Excel数据失败:"+textStatus+"
");
window.clearInterval(task);
});
});
uploader.init();
|