From 8f742b8e1487c70999f51eaf9d2df47942e9f91f Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 22 Dec 2020 20:40:01 +0100 Subject: [PATCH] Increase nginx upload limit to have a better message in the Django form --- apps/registration/forms.py | 13 +++++++------ nginx_corres2math.conf | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/registration/forms.py b/apps/registration/forms.py index 24e3588..5c4aec3 100644 --- a/apps/registration/forms.py +++ b/apps/registration/forms.py @@ -72,12 +72,13 @@ class PhotoAuthorizationForm(forms.ModelForm): Form to send a photo authorization. """ def clean_photo_authorization(self): - if "photo_authorization" not in self.files: - raise ValidationError(_("The uploaded file size must be under 2 Mo.")) - file = self.files["photo_authorization"] - if file.content_type not in ["application/pdf", "image/png", "image/jpeg"]: - raise ValidationError(_("The uploaded file must be a PDF, PNG of JPEG file.")) - return self.cleaned_data["photo_authorization"] + if "photo_authorization" in self.files: + file = self.files["photo_authorization"] + if file.size > 2e6: + raise ValidationError(_("The uploaded file size must be under 2 Mo.")) + if file.content_type not in ["application/pdf", "image/png", "image/jpeg"]: + raise ValidationError(_("The uploaded file must be a PDF, PNG of JPEG file.")) + return self.cleaned_data["photo_authorization"] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/nginx_corres2math.conf b/nginx_corres2math.conf index e4b01f0..06900b2 100644 --- a/nginx_corres2math.conf +++ b/nginx_corres2math.conf @@ -5,6 +5,7 @@ upstream corres2math { server { listen 80; server_name corres2math; + client_max_body_size 50M; location / { proxy_pass http://corres2math;