Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript | WebAPI | File | File.size Property

  • Last Updated : 18 Jan, 2019

The file.name property is an inbuilt function of file WebAPI which gives the size of a file in bytes.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

var size = instanceOfFile.size;

Return Value: It returns a number, containing the size of the file in bytes.

Example:






<!DOCTYPE html>
<html>
<head>
    <title>
        WebAPI File.name
    </title>
      
    <style>
        #main {
            padding: 10px;
            width: 300px;
            border: 1px solid black;
            text-align:center;
            font-size:22px;
        }
    </style>
</head>
  
<body>
    <div id = "main">
          
        <div>GeeksforGeeks</div>
        <div>file.size</div>
          
        <input type = "file" multiple id = "file_input"
            onchange = "myGeeks(this)">
    </div>
      
    <script type="text/javascript">
        function myGeeks(fileInput) {
              
            // File input
            var fileInput = document.getElementById("file_input");
      
            var files = fileInput.files;
              
            for (var i = 0; i < files.length; i++) {
                alert(files[i].name + " has a size of "
                + files[i].size + " Bytes");
            }
        }
    </script>
    </body>
</html>                    

Output:

Supported Browsers: The browser supported by WebAPI File.name property are listed below:

  • Edge
  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer
  • Safari

Reference: https://developer.mozilla.org/en-US/docs/Web/API/File/size




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!