DeLe
DeLe

Reputation: 2480

Get filesize on 'change function' before upload using Extjs

I want to get filesize when change function run. I try more but anything didn't work. How can i do that thanks

   {
        xtype: 'filefield',
        name: 'upfile[]',
        buttonConfig: {
            text: 'add'
        },
        listeners: {
              'change': function(f, value){
                    alert(f.size); // not filesize
              }
        }
    }

Upvotes: 0

Views: 4393

Answers (3)

angel fernandez
angel fernandez

Reputation: 21

listeners:{
    change:function(inputFile, value){
            console.log(inputFile.fileInputEl.dom.files[0].size)
     }
}

Upvotes: 1

Neil McGuigan
Neil McGuigan

Reputation: 48236

  1. the only universal solution is to upload the file to the server and get the file size back

  2. for modern browsers (IE10 and all the others), you can use the HTML5 FileReader API

    https://developer.mozilla.org/en-US/docs/Web/API/FileReader

  3. for IE 9 or less you can use Hariharan's solution

Upvotes: 1

Hariharan
Hariharan

Reputation: 3263

it is possible with ActiveX Objects.

function getSize()
{
    var myFSO = new ActiveXObject("Scripting.FileSystemObject");
    var filepath = document.upload.file.value;
    var thefile = myFSO.getFile(filepath);
    var size = thefile.size;
    alert(size + " bytes");
}

Please refer below link

http://www.sencha.com/forum/showthread.php?158445-How-can-i-get-the-size-of-the-file-before-upload

Upvotes: 0

Related Questions