Checking file size before disposing of it

Is there a way to check the file size before downloading it using javascript?

+4
source share
3 answers

Only in some browsers. There's a new API from W3C that allows very limited access to the file system from client Javascript in the browser. It works if the user explicitly allows you access to the file by selecting it in the <input type='file'> field. Then you can request its properties (not including the full path) and even read it directly without sending it to the server.

The API file was created by Mozilla and is supported by Firefox 3.6 up (earlier versions supported an earlier version). Chrome and Safari also have this, I reckon. Here's an article about this by Aruna Ranganatan from Mozilla.

So you can try to use it, and if it is there, big; if not, you are stuck not being able to do this on the client.

Naturally, he will want to impose restrictions on the file size on the server, regardless of whether you can do this on the client. Client-side validation is always convenient, not protecting your server.

+7
source

No - javascript does not have access to the file system. If you can use a flash gadget or silverlight to complete your downloads, you can do it.

+2
source

not.

And his royal pita. The best you can do is set file size limits on your receiving end and have enough checks to notify the user when they try to download something too large.

0
source

Source: https://habr.com/ru/post/1309560/


All Articles