私は 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
})
しかし、 fileobj がリーダーの外部で未定義として表示されます。 onload 関数。では、このファイルをその内容とともにサーバー側に送信する方法は? コントローラーでアップロードされたファイルを取得してサーバーに送信する他の方法はありますか。誰か私を案内してください。