How do I get human readable file size through javascript

Hi Friends,

Few days ago, I have write blog on human readable file size through c#.

Today I am going to represent same functionality using javascript.

For the above requirement, I have created one general function.

See the below code:

function GetFileSize(size)
     var fileUnits = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
     var fuCount = 0;

     while (size >= 1024)
                //size /= 1024;
                size = Math.round(size / 1024)

      return size + fileUnits[fuCount];

Put above function in your page header section.

you can call it as like below

var filesize = GetFileSize(file.size);

Here, I have passed file size as a parameter.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>