From 15ed9d81d59704b1283454a5ea5fd2718e796f1d Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Sun, 6 Sep 2020 12:16:36 +0200 Subject: [PATCH] Check image size before sending it --- .../templates/member/picture_update.html | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/member/templates/member/picture_update.html b/apps/member/templates/member/picture_update.html index 7c9128ce..326e3651 100644 --- a/apps/member/templates/member/picture_update.html +++ b/apps/member/templates/member/picture_update.html @@ -55,12 +55,18 @@ SPDX-License-Identifier: GPL-3.0-or-later /* SCRIPT TO OPEN THE MODAL WITH THE PREVIEW */ $("#id_image").change(function (e) { if (this.files && this.files[0]) { - var reader = new FileReader(); - reader.onload = function (e) { - $("#modal-image").attr("src", e.target.result); - $("#modalCrop").modal("show"); + // Check the image size + if (this.files[0].size > 2*1024*1024) { + alert("Ce fichier est trop volumineux.") + } else { + // Read the selected image file + var reader = new FileReader(); + reader.onload = function (e) { + $("#modal-image").attr("src", e.target.result); + $("#modalCrop").modal("show"); + } + reader.readAsDataURL(this.files[0]); } - reader.readAsDataURL(this.files[0]); } }); @@ -104,4 +110,4 @@ SPDX-License-Identifier: GPL-3.0-or-later }); }); -{% endblock %} \ No newline at end of file +{% endblock %}