From 056db7e3b0ca204d66e095a2bc3aa5bcd4e81e0a Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Nov 03 2015 20:43:44 +0000 Subject: 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 --- 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 %}