Arm*_*nce 0 c# extjs file-upload extjs4
我知道如何创建一个浏览和选择文件的表单,这不是我的问题.我需要的是获取所选文件的内容,将其发送到服务器并进行处理.现在我只能获取文件位置.
我认为如果我在客户端(extjs)获取文件然后将其发送到服务器会更好,但我不知道如何做到这一点.
{
xtype: 'fileuploadfield',
hideLabel: true,
emptyText: 'Select a file to upload...',
id: 'upfile',
//name:'file',
width: 220
},
buttons:
[
{
text: 'Upload',
handler: function () {
obj.Import(Ext.getCmp('upfile').getValue())
}
}
]
Run Code Online (Sandbox Code Playgroud)
Import(...)是我的服务器功能.我需要给它的文件不仅仅是它的路径!!
提前谢谢您的时间
AFAIK Ext不使用HTML5文件API,因此在JS端获取文件内容并不简单.可能最简单的方法是创建自定义处理程序.例如:
{
xtype: 'fileuploadfield',
hideLabel: true,
emptyText: 'Select a file to upload...',
id: 'upfile',
//name:'file',
width: 220
},
buttons:
[
{
text: 'Upload',
handler: function () {
var file = Ext.getCmp('upfile').getEl().down('input[type=file]').dom.files[0]; // fibasic is fileuploadfield
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
obj.Import(e.target.result);
};
})(file);
reader.readAsBinaryString(file);
}
}
]
Run Code Online (Sandbox Code Playgroud)