admin 管理员组文章数量: 1087134
I have form panel in ext js. Inside form panel using xtype: filefield
How to get uploaded file.
If I use form will get getForm()
method to get that file. Now, form is not available in ext js.
I use to get values like that
var values = form.getValues();
if(form.validate())
{
var name = values.name;
var desc = values.desc;
}
file field file I need to get and stored to DB. In this filefield upload a mp3 file. Anyone can suggest a solution for it.
I have form panel in ext js. Inside form panel using xtype: filefield
How to get uploaded file.
If I use form will get getForm()
method to get that file. Now, form is not available in ext js.
I use to get values like that
var values = form.getValues();
if(form.validate())
{
var name = values.name;
var desc = values.desc;
}
file field file I need to get and stored to DB. In this filefield upload a mp3 file. Anyone can suggest a solution for it.
Share Improve this question edited Dec 11, 2019 at 8:37 Jaydeep 1,7161 gold badge17 silver badges33 bronze badges asked Dec 11, 2019 at 8:29 sarathisarathi 1,0691 gold badge8 silver badges14 bronze badges2 Answers
Reset to default 4You can use FileReader
object to read the file. Below is the sample code to do it.
Ext.application({
name : 'Fiddle',
launch : function() {
Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
fullscreen: true,
items: [{
xtype: 'fieldset',
title: 'My Uploader',
items: [
{
xtype: 'filefield',
label: "MyPhoto:",
name: 'photo'
}, {
xtype: 'button',
text: 'Get File',
handler: function(){
let file = this.up().down('filefield').el.down('input[type=file]').dom.files[0];
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
let result = e.target.result;
//process upload with result
alert(result);
};
})(file);
reader.readAsBinaryString(file);
}
}
]
}]
});
}
});
You can find the working fiddle here
Alternatively you can use the form.submit()
method to submit the form.
var form = this.up('form').getForm();
if(form.isValid()) {
form.submit({
url: 'photo-upload.php',
waitMsg: 'Uploading your photo...',
success: function(fp, o) {
Ext.Msg.alert('Success', 'Your photo "' + o.result.file +
'" has been uploaded.');
}
});
}
You can find this example here
Have a look at fileInputEl You could register a change listener on the filefield and get the file from there, e.g.
listeners: {
change: function(field, fileName) {
var fileList = field.fileInputEl.dom.files;
for (var i = 0; i < fileList.length; i++) {
var file = fileList[i];
//do what ever you want with file
}
}
}
本文标签: javascripthow do i get file from filefield in ext jsStack Overflow
版权声明:本文标题:javascript - how do i get file from filefield in ext js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744067528a2527879.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论