summaryrefslogtreecommitdiffstats
path: root/activities
diff options
context:
space:
mode:
authorAndrew Godwin2022-12-02 04:02:38 -0700
committerAndrew Godwin2022-12-02 04:02:38 -0700
commit9f3ad0be16d556a36ac48ffbd461a31873c78055 (patch)
treee890d0546cd7f3f982b884572dbd88be3bbc9df7 /activities
parent630c9df113a82d57325083057ca913b478aa1eb6 (diff)
downloadtakahe-9f3ad0be16d556a36ac48ffbd461a31873c78055.tar.gz
takahe-9f3ad0be16d556a36ac48ffbd461a31873c78055.tar.bz2
takahe-9f3ad0be16d556a36ac48ffbd461a31873c78055.zip
Don't allow file uploads bigger than 10MB
Diffstat (limited to 'activities')
-rw-r--r--activities/views/compose.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/activities/views/compose.py b/activities/views/compose.py
index 58dc7fc..2fa0bbb 100644
--- a/activities/views/compose.py
+++ b/activities/views/compose.py
@@ -156,6 +156,17 @@ class ImageUpload(FormView):
image = forms.ImageField()
description = forms.CharField(required=False)
+ def clean_image(self):
+ value = self.cleaned_data["image"]
+ if value.size > 1024 * 1024 * 1:
+ # Erase the file from our data to stop trying to show it again
+ self.files = {}
+ raise forms.ValidationError("File must be 10MB or less")
+ return value
+
+ def form_invalid(self, form):
+ return super().form_invalid(form)
+
def form_valid(self, form):
# Make a PostAttachment
thumbnail_file = resize_image(form.cleaned_data["image"], size=(400, 225))