summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorKohei Yoshino <kohei.yoshino@gmail.com>2018-06-21 16:28:21 +0200
committerDylan William Hardison <dylan@hardison.net>2018-06-21 16:28:21 +0200
commit52100a9f4f2e5b5d3249934143fb9a7097f156f9 (patch)
tree54e797edabafd916669de10ae97b4fa4e952ee7c /js
parentfca89e2f4c4a0660d0ce8947f2de375ec20f124b (diff)
downloadbugzilla-52100a9f4f2e5b5d3249934143fb9a7097f156f9.tar.gz
bugzilla-52100a9f4f2e5b5d3249934143fb9a7097f156f9.tar.xz
Bug 1469333 - Check attachment file size client-side and inform user of too large file before uploading it
Diffstat (limited to 'js')
-rw-r--r--js/attachment.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/js/attachment.js b/js/attachment.js
index f967f64d3..6d6dae58d 100644
--- a/js/attachment.js
+++ b/js/attachment.js
@@ -93,6 +93,21 @@ function DataFieldHandler() {
}
}
}
+
+ // Check the current file size (in KB)
+ const file_size = field_data.files[0].size / 1024;
+ const max_size = BUGZILLA.param.maxattachmentsize;
+ const invalid = file_size > max_size;
+ const message = invalid ? `This file (<strong>${(file_size / 1024).toFixed(1)} MB</strong>) is larger than the ` +
+ `maximum allowed size (<strong>${(max_size / 1024).toFixed(1)} MB</strong>).<br>Please consider uploading it ` +
+ `to an online file storage and sharing the link in a bug comment instead.` : '';
+ const message_short = invalid ? 'File too large' : '';
+ const $error = document.querySelector('#data-error');
+
+ // Show an error message if the file is too large
+ $error.innerHTML = message;
+ field_data.setCustomValidity(message_short);
+ field_data.setAttribute('aria-invalid', invalid);
}
function clearAttachmentFields() {