views:

55

answers:

3

Hi All,

How can we restrict users from attaching file bigger than specified size (to say 20MB). I do have a check at the server side to show errors in case of big files received on the server but that happens too late.

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

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

Thanks!

Pratik

+2  A: 

Javascript does not have access to this kind of information, but a tool like swfupload can give you nice javascript api's to access this information with flash.

http://swfupload.org/

Alex Sexton
A: 

Use JQuery File Upload plugin.

Sarfraz
This, of course, has a jquery dependency. It also uses flash to detect the file sizes (much like swfupload), so just be warned.
Alex Sexton
@Alex: yes you are right just posted it because that's what i use it for the same purpose.
Sarfraz
A: 

In general, JavaScript should not be used for any restrictions of user actions since it is executed on the client side and can be manipulated. Flash suffers from the same problem.

Any restrictions should be implemented on the server side.

Techpriester
He stated that he uses serverside validation to assure that the file is the correct size, but he wants the user experience benefit of not waiting for the entire upload to find that out. The path for graceful degradation is clear and already implemented.
Alex Sexton
Yes, but a user should be told that their 4GB attachment is too big before they spend 97 hours uploading it!
Gabe