Skip to content

Commit

Permalink
Issue #993. Add clientside "image is too freaking big" validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Taylor committed Apr 5, 2016
1 parent deefd94 commit 5f27e4a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion webcompat/static/js/lib/bugform.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ function BugForm() {
// image should be valid by default because it's optional
'valid': true,
'helpText': 'Please select an image of the following type: jpg, png, gif, or bmp.'
},
'img_too_big': {
'elm': this.uploadField,
// image should be valid by default because it's optional
'valid': true,
'helpText': 'Please choose an image that is smaller than 4GB.'
}
};

Expand Down Expand Up @@ -222,6 +228,10 @@ function BugForm() {
inlineHelp.insertAfter('.wc-Form-label--upload');
}

if (id === 'img_too_big') {
inlineHelp.insertAfter('.js-image-upload');
}

this.disableSubmits();
};

Expand Down Expand Up @@ -250,7 +260,13 @@ function BugForm() {
// We can just grab the 0th one, because we only allow uploading
// a single image at a time (for now)
var img = event.target.files[0];
// One last validation check.
// The limit is 4GB (which is crazy big!), so let the user know if their
// file is unreasonably large.
if (img.size > 1024 * 1024 * 4) {
this.makeInvalid('img_too_big');
}

// One last image type validation check.
if (!img.type.match('image.*')) {
this.makeInvalid('image');
return;
Expand Down

0 comments on commit 5f27e4a

Please sign in to comment.