Skip to content

Instantly share code, notes, and snippets.

@vasilii-b
Created February 27, 2019 07:11
Show Gist options
  • Save vasilii-b/d52bf0b4520ee245cd1c2f9ae4ff01ff to your computer and use it in GitHub Desktop.
Save vasilii-b/d52bf0b4520ee245cd1c2f9ae4ff01ff to your computer and use it in GitHub Desktop.
Checks whenever the uploaded file matches allowed file maximum size
var uploadField = document.getElementById("file");
uploadField.onchange = function() {
if(this.files[0].size > 2097152){ // 2MB
alert("File is too big!");
this.value = "";
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment