By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
463,149 Members | 592 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 463,149 IT Pros & Developers. It's quick & easy.

Check File Size using JavaScript

Expert Mod 5K+
P: 9,731
Hi there!

I'm hoping that someone knows how to check the size of a file before it is uploaded to the server using JavaScript.

I have seen suggested solutions using an ActiveX control to check the file size; however, I'm not happy with this solution because my application is designed to work in multiple browsers and ActiveX is limited to Internet Explorer.

I cannot check the file size on the web server because IIS throws the following exception before my code is executed:
"System.Web.HttpException: Maximum request length exceeded"

I realize that the maximum request length can be increased, however according to my application's specifications the files uploaded (images) must be much less than 4MB in size (200K).

Any suggestions or recommendations about how to check the file size using JavaScript are welcome.


Jan 19 '09 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 9,731
I think that what I'm asking is impossible.
I have recently come across an explanation as to why:

Browser security does not allow Scripts to read files from the local hard drive. This means that the input type "File" doesn't have permissions to read files. Therefore, there is no way to use JavaScript to check the file size.

Jan 19 '09 #2

rnd me
Expert 100+
P: 427
you can do it in firefox3; file inputs provide a getAsBinary method.

the length of the resulting string is your filesize.

IE can use the activeX stuff.
Jan 19 '09 #3

Expert Mod 5K+
P: 9,731
Do you know of any solutions for Opera and Safari as well?

I've started looking into a server side fix for this so that it can work in any browser. The main ones I test with are IE, FireFox, Opera and Safari.
Jan 19 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.