From 501491ac9a52ed42185ed2588d7e965bc56a7ccf Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Mon, 12 Nov 2018 17:26:36 +0100 Subject: [PATCH] Added file size check --- parts/static/script.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/parts/static/script.js b/parts/static/script.js index 9dfc048..3e5b1df 100644 --- a/parts/static/script.js +++ b/parts/static/script.js @@ -73,12 +73,17 @@ function save(partID) { } var data = new FormData(); - if (datasheet.length == 1) + if (datasheet.length == 1) { if(! datasheet[0]['name'].match(/^[\w\-]+\.pdf$/g)) { alert('Invalid filename. Please match /^[\w\-]+\.pdf$/g'); return; } + if (datasheet[0]['size'] > 20 * 1000000) { + alert('File too large. Must be < 20MB.'); + return; + } data.append('datasheet-file', datasheet[0]); + } data.append('partno', partno_v); data.append('location_id', location_id_v) data.append('description', description_v);