Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get byte array of file from filefield ExtJs

Tags:

extjs

extjs5

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.

like image 989
Tato Avatar asked Dec 10 '14 19:12

Tato


1 Answers

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/

like image 64
Krzysztof Avatar answered Oct 21 '22 07:10

Krzysztof