Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting file size in javascript

Tags:

javascript

given a path of a file like:
C:\file.jpg
how can i get the size of the file in javascript?

like image 393
scatman Avatar asked Jun 03 '10 12:06

scatman


People also ask

How do I check the size of a JavaScript file?

To check file size using HTML5 and JavaScript, we can use a file input and check the file's size after selecting the file. document. getElementById("fileInput"). onchange = () => { const fileSize = document.

How do I check the size of a node js file?

To get the size of a file in Node. js, you can use the stat() method provided by the built-in fs module. This method works asynchronously and lists the statistics of a file at the given path. The size of the file is returned in bytes.


1 Answers

If it's not a local application powered by JavaScript with full access permissions, you can't get the size of any file just from the path name. Web pages running javascript do not have access to the local filesystem for security reasons.

You can use a graceful degrading file uploader like SWFUpload if you want to show a progress bar. HTML5 also has the File API, but that is not widely supported just yet. If a user selects the file for an input[type=file] element, you can get details about the file from the files collection:

alert(myInp.files[0].size); 
like image 89
Andy E Avatar answered Sep 22 '22 08:09

Andy E