Created
December 3, 2012 21:29
Revisions
-
keenahn revised this gist
Dec 3, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ validate_file = -> else if size and size > 5242880 alert "Please choose a file of size 5MB or smaller" return else if name ext = name.substr(name.lastIndexOf(".") + 1).toLowerCase() if ext isnt "jpg" and ext isnt "gif" and ext isnt "png" and ext isnt "jpeg" alert "Please choose an image of type 'jpeg', 'jpg', 'png', or 'gif'" -
keenahn revised this gist
Dec 3, 2012 . 2 changed files with 24 additions and 30 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,30 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ # Just some examples of how to do file validation with javascript # IS NOT BULLETPROOF and should be coupled with server side validation # But, it can help validate_file = -> file = @fileInput.files[0] if "name" of file name = file.name else name = file.fileName if "size" of file size = file.size else size = file.fileSize if not file or not file.type.match(/image.*/) alert "Only image files can be uploaded" return else if size and size > 5242880 alert "Please choose a file of size 5MB or smaller" return else if name and name ext = name.substr(name.lastIndexOf(".") + 1).toLowerCase() if ext isnt "jpg" and ext isnt "gif" and ext isnt "png" and ext isnt "jpeg" alert "Please choose an image of type 'jpeg', 'jpg', 'png', or 'gif'" return -
keenahn created this gist
Dec 3, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ // Just some examples of how to do file validation with javascript // IS NOT BULLETPROOF and should be coupled with server side validation // But, it can help var file = this.fileInput.files[0]; if ('name' in file) { name = file.name } else { name = file.fileName } if ('size' in file) { size = file.size } else { size = file.fileSize } if (!file || !file.type.match(/image.*/)) { this.onError("Only image files can be uploaded"); return; } else if(size && size > 5242880){ this.onError("Please choose a file of size 5MB or smaller"); return; } else if(name && name){ ext = name.substr(name.lastIndexOf('.') + 1).toLowerCase() if(ext != "jpg" && ext != "gif" && ext != "png" && ext != "jpeg") { this.onError("Please choose an image of type 'jpeg', 'jpg', 'png', or 'gif'"); return; } }