Add max file size check when uploading a letter

This commit is contained in:
Katie Smith
2019-09-06 11:13:05 +01:00
parent be6b5b922a
commit a103dbf801
2 changed files with 20 additions and 0 deletions

View File

@@ -9,6 +9,8 @@ from app.main import main
from app.main.forms import PDFUploadForm
from app.utils import user_has_permissions
MAX_FILE_UPLOAD_SIZE = 2 * 1024 * 1024 # 2MB
@main.route("/services/<service_id>/uploads")
@user_has_permissions('send_messages')
@@ -29,6 +31,10 @@ def upload_letter(service_id):
flash('Your file has failed the virus check', 'dangerous')
return render_template('views/uploads/choose-file.html', form=form), 400
if len(pdf_file_bytes) > MAX_FILE_UPLOAD_SIZE:
flash('Your file must be smaller than 2MB', 'dangerous')
return render_template('views/uploads/choose-file.html', form=form), 400
upload_id = uuid.uuid4()
return redirect(