From: Rob Crittenden Date: Tue, 3 Nov 2015 15:26:36 +0000 (-0500) Subject: Verify that uploaded files are readable when selected X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=commitdiff_plain;h=cae2c6d2b98b2981458e06f3700d0e0d27e1a2dc;ds=sidebyside Verify that uploaded files are readable when selected When selecting a file using file input this doesn't guarantee that the file contents are readable. No real error is provided in this case, things just don't work as expected. When adding a SAML SP and the metadata file or image is provided via file upload try to read the file in the browser first and pop up an alert if it is unreadable. https://fedorahosted.org/ipsilon/ticket/22 Signed-off-by: Rob Crittenden Reviewed-by: Simo Sorce Reviewed-by: John Dennis --- diff --git a/templates/admin/option_config.html b/templates/admin/option_config.html index 02babe6..14326fd 100644 --- a/templates/admin/option_config.html +++ b/templates/admin/option_config.html @@ -38,7 +38,13 @@ var reader = new FileReader(); // instance of the FileReader reader.readAsDataURL(files[0]); // read the local file - reader.onloadend = function(){ // set image data as background of div + reader.onloadend = function(e){ // set image data as background of div + var contents = e.target.result; + if (!contents) { + window.alert('Image file is unreadable') + document.getElementById('uploadFile').value = null; + } + $("#imagePreview").css("background-image", "url("+this.result+")"); } } diff --git a/templates/admin/providers/saml2_sp_new.html b/templates/admin/providers/saml2_sp_new.html index 1c95355..13f1a9e 100644 --- a/templates/admin/providers/saml2_sp_new.html +++ b/templates/admin/providers/saml2_sp_new.html @@ -69,4 +69,39 @@ Back + + {% endblock %}