Hello friends I have the following filefield
:
{
xtype:'filefield',
buttonText: 'choose',
buttonOnly: true,
listeners: {
change: function(fb, v) {
// ...
}
}
}
and I want to get the chosen file in a byte array
Please help me if you can.
AFAIK Ext JS doesn't support that out of box, but you can easily implement that using JS File API. Example:
// file filed component reference
var filefield = [...];
// get file dom element
var file = filefield.getEl().down('input[type=file]').dom.files[0];
// create reader
var reader = new FileReader();
// create handler
reader.onload = (function(theFile) {
return function(e) {
// process file
console.log(e.target.result);
};
})(file);
// start upload
reader.readAsBinaryString(file);
Fiddle: http://jsfiddle.net/qjt6j0jv/2/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With