Open In App

JavaScript WebAPI File.size Property

Last Updated : 30 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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

Syntax:

let size = instanceOfFile.size;

Return Value:

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

Example: This example shows the implementation of the JavaScript WebAPI File.size Property.

html
<!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
            let fileInput = document.getElementById("file_input");

            let files = fileInput.files;

            for (let 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
  • Safari


Next Article
Article Tags :

Similar Reads