JavaScript | WebAPI | File | File.size Property
The file.name property is an inbuilt function of file WebAPI which gives the size of a file in bytes.
Syntax:
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> |
chevron_right
filter_none
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
Recommended Posts:
- JavaScript | WebAPI | File | File.type Property
- JavaScript | WebAPI | File | File.name Property
- PHP | filesize( ) Function
- How to include a JavaScript file in another JavaScript file ?
- How to get file extensions using JavaScript?
- How to get the file name from full path using JavaScript ?
- Javascript | Program to read text File
- How to trim a file extension from string using JavaScript ?
- Validation of file size while uploading using JavaScript / jQuery
- How to reset input type = "file" using JavaScript/jQuery?
- JavaScript | Program to write data in a text File
- JavaScript | Error name Property
- JavaScript | Infinity Property
- JavaScript | undefined Property
- JavaScript | Cursor property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



