0

Ok, this is frustrating. I have searched a lot on google on how to validate selected file (to upload) extension and size but no success on the file size matter. I have an image upload control in asp.net (meant to upload images) but the extension and file size is validated on the server. That's how it works. What if the user submits a 1GB file that is a movie renamed to .jpg?

Somehow Twitter for example managed to validate the input file on client side, both extensions and file size. Anyone got any ideas how to do that before submitting to the server?

Thanks!

LE: No, no HTML5. It's not supported in all browsers. I need a solution to work in IE 7 and 8 also!

2

2 Answers 2

3

If the user browser supports the html5 fileapi, you can read a file size from the file input.

document.getElementById('file').files[0].size  //size of file in bytes
document.getElementById('file').files[0].name  //name of file
document.getElementById('file').files[0].type  //mime type
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for answering, but correct me if i'm wrong, html5 is not supported in all modern browsers. IE 7 and 8 , probably event 9 doesn't support it? I need a method to work on those too.
You say modern browsers but you call IE7 and 8(and 9)? If you want this to work in all these browsers which I don't think is a good idea, you may have to look into browser specific solutions, like ActiveXObject in IE or even dum dum dum Flash.
0

The HTML5 api, as pointed out by Musa, would probably filter out the majority of cases.

There are proprietary ActiveX methods that may do this too, but support is a bit of an unknown.

Flash can do the check for you if you insist on no html5, you could look in to something like swfupload https://code.google.com/p/swfupload/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.