5

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.

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
Tato
  • 195
  • 4
  • 17

1 Answers1

12

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/

Krzysztof
  • 15,900
  • 2
  • 46
  • 76