Client Checking File Size Using HTML5



Before HTML5, the file size was checked with flash but now flash is avoided in web apps. Still the file size on the client side can be checked by inserting the below given code inside an event listener.

if (typeofFileReader !== "undefined") {
   // file[0] is file 1
   var s = document.getElementById('myfile').files[0].size;
}

On file input change, the size will update. For that, use event listener,

document.getElementById('input').onchange = function() {
   // file[0] is file 1
   var s = document.getElementById('input').files[0].size;
   alert(s);
}
Updated on: 2020-03-04T05:02:06+05:30

368 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements