我正在处理 Extjs4 文件上传控件。我有一个视图,其中包含文件上传控件,如下所示 -
Ext.define('Balaee.view.kp.dnycontent.Content',
{
extend:'Ext.form.Panel',
requires:[
'Balaee.view.kp.dnycontent.ContentView'
],
id:'ContentId',
alias:'widget.Content',
enctype : 'multipart/form-data',
title:'This day in a history',
items:[
{
xtype: 'fileuploadfield',
hideLabel: true,
emptyText: 'Select a file to upload...',
//inputType: 'file',
id: 'upfile',
width: 220
}],
buttons: [{
xtype : 'button',
fieldlabel:'upload',
action:'upload',
name:'upload',
text: 'Upload',
formBind:'true'
}]
});
对应的控制器中的操作代码如下:
getUpload : function() {
var file10 = Ext.getCmp('ContentId').getEl().down('input[type=file]').dom.files[0];
var reader = new FileReader();
reader.onload = function(oFREvent) {
fileobj=oFREvent.target.result;
console.log(oFREvent.target.result);
};
}
});
以上控制器的功能是检索上传的文件并在读取器的onload函数中以编码格式显示它。即,“console.log(oFREvent.target.result);”行在控制台中以编码格式显示上传文件的数据。我需要将此文件发送到服务器端。因此,我将上述fileobj作为参数传递以存储为 -
var storeObj=this.getStore('kp.DnycontentStore');
storeObj.load({
params:{
data:fileobj
},
callback: function(records,operation,success){
console.log("send");
},
scope:this
})
但是在reader.onload函数外部,它显示fileobj未定义。那么如何将此文件及其内容发送到服务器端?是否有其他方法在控制器中获取上传的文件并将其发送到服务器?请问有人可以指导我吗。