Limit attachment of large files with Javascript

How can we prevent users from attaching a file larger than the specified size (say, 20 MB). I have a server side check to show errors in the case of large files received on the server, but this happens too late.

I want to achieve something like gmail where you get a quick alert indicating

"This file exceeds the 25MB attachment limit. Sorry."

Thank!

Pratik

+3
source share
3 answers

Javascript does not have access to this information, but a tool like swfupload can give you a good javascript api for accessing this information with flash.

http://swfupload.org/

+2
source
0

In general, JavaScript should not be used for any restrictions on the user's actions, since it is executed on the client side and can be controlled. Flash has the same problem.

Any restrictions must be implemented on the server side.

0
source

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


All Articles