Don't allow file uploads bigger than 10MB
This commit is contained in:
parent
630c9df113
commit
9f3ad0be16
|
@ -156,6 +156,17 @@ class ImageUpload(FormView):
|
||||||
image = forms.ImageField()
|
image = forms.ImageField()
|
||||||
description = forms.CharField(required=False)
|
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):
|
def form_valid(self, form):
|
||||||
# Make a PostAttachment
|
# Make a PostAttachment
|
||||||
thumbnail_file = resize_image(form.cleaned_data["image"], size=(400, 225))
|
thumbnail_file = resize_image(form.cleaned_data["image"], size=(400, 225))
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ field }}
|
{{ field }}
|
||||||
</div>
|
</div>
|
||||||
{% if field.field.widget.input_type == "file" and field.value%}
|
{% if field.field.widget.input_type == "file" and field.value %}
|
||||||
<img class="preview" src="{{ field.value }}">
|
<img class="preview" src="{{ field.value }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue