Reputation: 5528
Is there any way to check for file format and size of the file before uploading it in javascript?
Upvotes: 1
Views: 827
Reputation: 4331
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.)
Upvotes: 0
Reputation: 382909
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.
Upvotes: 5
Reputation: 31590
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) {
alert(theFile.size);
})(fileTobeUploaded);
Upvotes: 0