Getting File size in JavaScript 


In this blog you will learn that how you can get size of file in JavaScript so that you can validate it as per your choice - 

How to get size of a file in javascript

 

 

Step 1- This is our HTML of the program 

	
<h2>Choose file to check the size</h2>
    
    <input type="file" id="header-image" >
    


 Step 2 - This is the JavaScript of the program

	
    var file = document.getElementById("header-image");
            file.addEventListener('change', function () {
                var image = this.files[0];
                alert(image.size/1024+"kb");
                
            });
    




 Output - 

how to get file size in javascript