Take the 2-minute tour ×

Is there any way to check for file format and size of the file before uploading it in javascript?

share|improve this question

3 Answers 3

up vote 5 down vote accepted

No, that's not possible. You can check for the extension but still it could be wrong because a text file renamed to zip will show you zip as an extension. You need server-side script for that.

Once file is uploaded, you can check its mime-type and size with server-side script.

share|improve this answer

Assuming you've obtained the fileTobeUploaded object (i don't know how you are doing the upload), with the following you could get the size in bytes.

var reader = new FileReader();
reader.onload = (function(theFile) {
share|improve this answer
And the users has to be using Firefox 3.6 or later to use this... –  epascarello Nov 12 '10 at 14:39

I believe you can retrieve size information about the file using FLASH, however to determine the file format, you will most probably need to rely on the file extension... and that's a weak determination with regards to security (malware etc.)

share|improve this answer

Your Answer


